Memory Refresh
Php



Reference






Programming Regex, Antipatterns, Php, Git

Passed by reference

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

Default values

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







Programming Regex, Antipatterns, Php, Git