【URL】
https://www.w3schools.com/php/php_variables_scope.asp
【コード】
<!DOCTYPE html>
<html>
<body>
<?php
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo “<p>Variable in func:”
. $GLOBALS[‘x’]. “</p>”;
}
myTest();
echo “<p>Variable outside func:” . $x . “</p>”;
?>
</body>
</html>
コメント