MemoryRefresh!

Function / Reference   Reference



Questions Answers 0%

Pages   0 from 91
Questions   0 from 142

Reset


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

Related Pages

Definition
Variables
Anonymous
Reference


0% 100%
 
 
0 pages 91 pages
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









Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References