ExpertRefresh

Function / Reference  

Related Pages

Definition
Variables
Anonymous
Reference


0.0% 100%
 
 
0 pages 298 questions
1) Is this code valid? <?php function ($var1, &$var2 = null) {}





2) Which is the correct? <?php function _____ {} test($a, $count); echo $count; // Output: c






Function arguments can also be passed by reference, as opposed to the traditional by-value method, by prefixing them with the by-reference operator & <?php function myFind($str, $char, &$count) { // -- Look Here -- // for($i=0; $i<strlen($str); $i++) if ($str[$i] == $char) $count++; } myFind("abca", "a", $count); echo $count; // output 2 Unlike PHP 4, PHP 5 allows default values to be specified for parameters even when they are declared as by-reference: <?php function test($var1, &$var2 = null) { $var2 = "c"; } $var1 = 'a'; $var2 = 'b'; test($var1, $var2); echo $var2; // Output: c


References