minte9
LearnRemember



Reference

Function arguments can be passed by reference.
 
/**
 * Function arguments, passed by reference
 */

function findAndCount($s, $char, &$j) // Look Here
{
    $i = 0;
    while($i < strlen($s)) {
        if ($s[$i] == $char) 
            $j++;
        $i++;
    }
}

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

echo $count; // 2

Default values

PHP allows default values, even when parameters are declared as by-reference.
 
/**
 * Default function arguments
 */

function test($x, &$y = null) 
{
    $y = 100;
}

$x = 1;
$y = 2;

test($x, $y);
echo $y; // 100



  Last update: 303 days ago