PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Passed by reference

Function arguments can be passed by reference.
 
function myFind($str, $char, &$count) 
{
    for($i=0; $i<strlen($str); $i++) {
        if ($str[$i] == $char) $count++;
    }
}

myFind("abca", "a", $count);

echo $count; // output 2
... 3 lines
 

Default values

! PHP allows default values. Even when parameters are declared as by-reference.
 
function test($var1, &$var2 = null) 
{
    $var2 = "c";
}

$var1 = 'a';
$var2 = 'b';

test($var1, $var2);

echo $var2; // Output: c
... 3 lines
 

Questions    
Function variable scope

        A B C D E F
🔔
1/2