I am trying to make the $x
output the static nature as I have tried in the code below, I wasn't able to do that simple so i tried using the global array (as i can't access the variable that i declared outside the function), So i tried using the global array which didn't work either, next I tried to achieve the same by using the global keyword
, but latter didn't work either can someone suggest me what i am doing wrong?
<?php
global$x=5;
global$y=10;
global static $s=0;
$s=$x + $y;
//echo $s;
function willthiswork(){
//GLOBAL['s']=GLOBAL['x']+GLOBAL['y'];
$s=$x+$y;
$s++
}
willthiswork();
willthiswork();
willthiswork();
?>
I am really new with php and using this link to learn if there's any better resource please do mention it. https://www.w3schools.com/php/php_variables.asp