doghouse308 Posted November 6, 2014 Share Posted November 6, 2014 Is it possible to have a static variable in php? I want the value of a variable to remain unchanged the next time a function is called. Quote Link to comment https://forums.phpfreaks.com/topic/292305-static-variable/ Share on other sites More sharing options...
Solution requinix Posted November 6, 2014 Solution Share Posted November 6, 2014 (edited) As long as you're not calling the function on a different page load, yes. static function counter() { static $i = 1; return $i++; } echo counter(); // 1 echo counter(); // 2 echo counter(); // 3 Edited November 6, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/292305-static-variable/#findComment-1495889 Share on other sites More sharing options...
doghouse308 Posted November 6, 2014 Author Share Posted November 6, 2014 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/292305-static-variable/#findComment-1495940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.