function fn1()
{
    global $rows;
    global $row;
    $a = "rows";
    $b = "row";
    // TYPICAL FOREACH
    foreach ($rows as $row) {
        fn2();
    }
    // USING VARIABLE VARIABLE
    foreach (${$a} as ${$b}) {
        fn2();
    }
    // THE MALFORMED ARRAY
    foreach ($rows as $row) {
        fn2();
    }
}
Esempio n. 2
0
function fn()
{
    //echo "inside the function, \$var = ".$var."<br/>";
    $var = "contents 2";
    echo "inside the function, \$var = " . $var . "<br/>";
}
$var = "contents 1";
fn();
echo "outside the function, \$var = " . $var . "<br/>";
function fn2()
{
    global $var;
    $var = "contents";
    echo "inside the function, \$var = " . $var . "<br/>";
}
fn2();
echo "outside the function, \$var = " . $var . "<br/>";
/*未改变原变量的引用*/
function increment1($value, $amount = 1)
{
    $value = $value + $amount;
}
echo "without '&': <br/>";
$a1 = 10;
echo $a1 . "<br/>";
increment1($a1);
echo $a1 . "<br/>";
/*引用传递参数*/
function increment2(&$value, $amount = 1)
{
    $value = $value + $amount;
Esempio n. 3
0
function to_string()
{
    return fn2('ecToString', atLeastOneArg(func_get_args()));
}