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 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. 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 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!!!! 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
Archived
This topic is now archived and is closed to further replies.