PHP Program how to use static variable example


php source ( why we use static keyword )

<!DOCTYPE html>
<html>
<body>

<?php
function myTest() {
     static $x = 0;
     echo $x;
     $x++;
}

myTest();
echo "<br>";
myTest();
echo "<br>";
myTest();
?>
  

</body>
</html>

Output

0
1
2

0 comments:

Post a Comment

My Instagram