In the example of the PHP global keyword, the output is not equal to 15 but is actually equal to 10
石岳
石岳 2018-07-25 16:57:37
0
2
1203

The code is as follows

<?php

$x=5;

$y=10;

function myTest()

{

global $x,$y;

$y=$x $y;

}

myTest();

echo $y; // Output 15

?>


石岳
石岳

reply all(2)
ringa_lee

The answer is 10, that’s right. First of all, you have to understand the definition of the keyword global. There is a big difference between global and $GLOBALS. $GLOBALS defines variables as global variables. If it is defined by $GLOBALS, the result will be natural. It is 15, and global is used as a reference. Please note that the reference is not a pointer, and it cannot ultimately change the result of $x or $y!

范珺

It seems to be 15

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template