Hello everyone.
This is adcoder, a brand new member of the world of phpbuilder. Hoooo. How excited I was when i was surfing this site when i was thinking to jump into the world of web development. And today I am here.
I have no solid background of web development and php and other web development languages.
While in the meanwhile i found a book which is very brief but many things are discussed in it. Here i am here with a code where function is using with local and global variables; that how to use a global variable inside a local function by using global keyword.
Here is the code:
$number = 50;
function tenTimes() {
global $number;
$number = $number * 10;
}
tenTimes();
echo $number;
I was expecting that this code result will be 50 because i thought that
$number = 50;
is globally declared and it is also used inside the function but in the function there is no echo or print statement and the only echo statement outside the body of the function will just output the 50 but the result is 500.
Why the result is 500 instead of 50? Even there is no echo statement inside the function body?
Thanks