Why $GLOBALS['y'] is 10
牧云软件园
牧云软件园 2018-11-14 17:12:19
0
2
1259

<?php
$x=10;
$y=20;
function test(){
global $x,$y; //Use global keyword

$y=$x $y;
}
test();
echo $y;


##<? php

$x=5;

$y=10;

function myTest()

{

$GLOBALS['y']=$GLOBALS['x'] $GLOBALS['y'];

}

myTest();

echo $y;

?>

Are these two writing methods the same? Why is the returned result one 30 global $y

牧云软件园
牧云软件园

牧云软件园

reply all(1)
Summer

Only the first $y is a global variable

  • reply It seems that external global variables cannot be changed inside a function.
    牧云软件园 author 2018-11-19 09:14:11
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template