What output results from the following code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What output results from the following code?

<?php $num1 = 56; function my_func() { $num1 = 89; echo $num1; } my_func(); ?>

31st Dec 2017, 10:37 AM
Abo Mujahed
7 Answers
+ 5
89
31st Dec 2017, 10:44 AM
Programmer
Programmer - avatar
+ 2
89
8th Nov 2020, 3:08 PM
Abduvosi Abdugafforov
Abduvosi Abdugafforov - avatar
+ 1
89
23rd Apr 2019, 4:49 PM
Mwinibalonno Godfred
+ 1
89
16th Dec 2020, 11:08 AM
Hasan A.R
Hasan A.R - avatar
+ 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
14th Mar 2022, 6:37 PM
Diego Decort
0
Ok 89, thanks, but I don't understand why? Somebody can explain me (I'm a begginer) Thanks
25th Sep 2021, 4:20 PM
Germán Badia
Germán Badia - avatar
0
89
17th Jan 2023, 12:34 PM
Dhruv Shah
Dhruv Shah - avatar