![]() |
|
PHP advanced user defined functions. Free online PHP and MySQL Web Database Programming Tutorial... |
| Lessons | PHP User Defined Functions 2 |
|
|
<?php function add_extra(&$string) { $string .= 'and this is extra string.'; } $str = 'This is a string, '; add_extra($str); echo $str; // outputs 'This is a string, and this is extra string. ?> A function in PHP can't return multiple values, but similar result can be obtained by returning an array as shown below: <?php function numbers() { return array (0, 1, 2, 3); } ?> To return a reference from a function, we have to use the reference operator & in both the function declaration and when assigning the returned value to a variable as shown in the following example: <?php function &returns_ref() { return $someref; } $newref =& returns_ref(); ?>
Next: PHP Classes and Objects
|