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