search

Home  >  Q&A  >  body text

Calling a global variable cannot change the value of X

<?php

header("Content-type:text/html;charset=utf-8");

$x=5; // Global variables


function myTest()

{

$y=10; // Local variable

global $x;

echo "<p>Variables in the test function:<p>";

echo "Variable x is: $x";

echo "<br>" ;

echo "Variable y is: $y";

}


myTest();


echo "<p>Test function external variable:<p>";

echo "Variable x is: $x";

echo "< ;br>";

echo "Variable y is: $y"; //Output error Notice: Undefined variable:

?>


# #

蓝翔特级**蓝翔特级**2386 days ago1217

reply all(2)I'll reply

  • 尹天仇

    尹天仇2018-11-28 14:44:59

    This is a problem with his editor. You can try it in your own editor and it will display normally

    reply
    0
  • ll

    ll2018-08-13 17:27:34

    .... Take a closer look. $y is a local variable. You must have made an error when echoing $y outside the function. This variable is not defined

    reply
    0
  • Cancelreply