|
PHP. Functions and scope of view, PART 2 |
Function doesnt see outer variable: <? $a=2; function aaa (){ echo "rezultatas $a <br>"; } aaa(); ?>Inner function variable is not seen in outer code: <?
$a=2; function bbb (){ $a=3; echo "vidinis $a <br>"; } bbb(); echo "$a <br>"; //2
?><?
$a=2; function ccc (){ $a=3; return $a; } ccc(); echo "$a <br>"; // 2
?>Related variables: <?
$a=2;
function surisimas (&$b){ $b=10; }
surisimas($a); echo "$a <br>"; // 10
?><? $a=2;
function ddd ($b){ $b=10; }
ddd(&$a);
echo "$a <br>"; //10
?>Return array: <?
function eee (){ return array ("jonas", "petras", "simas"); }
list ($a, $b, $c )=eee(); echo "$c <br>";// simas
?>
|