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. Link to comment https://forums.phpfreaks.com/topic/292305-static-variable/ Share on other sites More sharing options...
requinix Posted November 6, 2014 Share Posted November 6, 2014 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 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! Link to comment https://forums.phpfreaks.com/topic/292305-static-variable/#findComment-1495940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.