static Keyword in PHP

Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job.
To do this, use the static keyword when you first declare the variable:

Example

<!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

---------------------- ------

Then, each time the function is called, that variable will still have the information it contained from the last time the function was called.

Previous
Next Post »

1 comments:

Click here for comments
Anonymous
April 12, 2022 at 4:10 PM ×

Static Keyword In Php ~ System Help Line >>>>> Download Now

>>>>> Download Full

Static Keyword In Php ~ System Help Line >>>>> Download LINK

>>>>> Download Now

Static Keyword In Php ~ System Help Line >>>>> Download Full

>>>>> Download LINK 8v

Selamat Anonymous dapat PERTAMAX...! Silahkan antri di pom terdekat heheheh...
Balas
avatar
admin
Thanks for your comment