thisisnuts123 Posted November 3, 2007 Share Posted November 3, 2007 hello guys phpfunction () { if ( $ a = $ b ) { phpvar++; } ...... } every time this funtion is called.. phpvar will get reset to zero.. is there a way to keep it;s value? store it some where so when it;s called the 2nd time it becomes 2 then 3 etc etc Quote Link to comment https://forums.phpfreaks.com/topic/75885-solved-keeping-value-of-a-variable/ Share on other sites More sharing options...
trq Posted November 3, 2007 Share Posted November 3, 2007 If you want it stored perminently you'll need to write it to eaither a file or a database. Otherwise, you might simply store it in the $_SESSION array. Quote Link to comment https://forums.phpfreaks.com/topic/75885-solved-keeping-value-of-a-variable/#findComment-384076 Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 if your using php 5 you can use the static keyword phpfunction () { static $phpvar = 0; if ( $ a == $ b ) { $phpvar++; } ...... } more info on http://php.net/static Quote Link to comment https://forums.phpfreaks.com/topic/75885-solved-keeping-value-of-a-variable/#findComment-384077 Share on other sites More sharing options...
thisisnuts123 Posted November 3, 2007 Author Share Posted November 3, 2007 u are the man thanks!!!! Quote Link to comment https://forums.phpfreaks.com/topic/75885-solved-keeping-value-of-a-variable/#findComment-384078 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.