0
What output results from the following code?
<?php $num1 = 56; function my_func() { $num1 = 89; echo $num1; } my_func(); ?>
7 Respuestas
+ 5
89
+ 2
89
+ 1
89
+ 1
89
+ 1
Answer is 89 because echo command is inside with in a function same as variable with value 89 what we call Local scope.Variable with value 56 is outside function and command echo inside so the result cant be 56.If we want to call variable with value 56 from command echo within a function the we should use global keyword or just we need to put echo command outside function which we call global scope then
0
Ok 89, thanks, but I don't understand why?
Somebody can explain me (I'm a begginer)
Thanks
0
89