PHP Program how to use global keyword to access global variable


php source ( how to use global keyword in php )

<!DOCTYPE html>
<html>
<body>

<?php
$x = 5;
$y = 10;

function myTest() {
     global $x, $y;
     $y = $x + $y;
}

myTest(); // run function
echo $y; // output the new value for variable $y
?>


</body>
</html>

output

15

0 comments:

Post a Comment

My Instagram