Homonymous Function Variables in PHP
Changes to internal function variables do not affect external variables with the same name:
<?php
$num = 1;
function func()
{
$num = 2;
}
func();
echo $num; // 1
?>
Explain what the result of executing the code will be:
<?php
$aaa = 111;
function func()
{
$aaa = 222;
}
func();
echo $aaa;
?>
Explain what the result of executing the code will be:
<?php
$aaa = 111;
function func()
{
$aaa++;
}
func();
echo $aaa;
?>
Explain what the result of executing the code will be:
<?php
$aaa = 111;
function func()
{
$aaa = 222;
return $aaa;
}
echo func();
?>