etrader Posted May 19, 2011 Share Posted May 19, 2011 I want to give a unique ID for each run of my php script. I was thinking of creating an array(1,2,3,4,5...), as I can regularly take the first value and delete. Is there any command like array_ shift to do so? array_ shift take the first item but does not permanently delete it; thus, it will be the first item again in the next run. Or do you have a subtle idea for assigning unique ID to each run? Link to comment https://forums.phpfreaks.com/topic/236857-unique-id-by-array_-shift/ Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 well you can you can set a variable to a value...say one...for this example we'll say that $i=1, and at the end of your script you could say $1++ which will increment the number every time the script is run...there are numerous ways to do what you want...you could tweak your idea a, use what i told you , you a database...sessions etc.. Link to comment https://forums.phpfreaks.com/topic/236857-unique-id-by-array_-shift/#findComment-1217541 Share on other sites More sharing options...
tbare Posted May 19, 2011 Share Posted May 19, 2011 fugix meant: <?php $i++; ?> , not $1++... simple typo Link to comment https://forums.phpfreaks.com/topic/236857-unique-id-by-array_-shift/#findComment-1217543 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 fugix meant: <?php $i++; ?> , not $1++... simple typo yeah ...lol thanks Link to comment https://forums.phpfreaks.com/topic/236857-unique-id-by-array_-shift/#findComment-1217595 Share on other sites More sharing options...
Pikachu2000 Posted May 19, 2011 Share Posted May 19, 2011 That won't work. If you initialize a variable at the beginning of a script and increment it at the end, when the script runs again, the variable is initialized again at the same value as the last time the script ran, not the incremented value. You're going to need to store a value in a database or in a file and increment the value that way. Link to comment https://forums.phpfreaks.com/topic/236857-unique-id-by-array_-shift/#findComment-1217640 Share on other sites More sharing options...
etrader Posted May 19, 2011 Author Share Posted May 19, 2011 You are quite right Pikachu2000. This cannot be a practical solution. I resolved it by storing the last value. Link to comment https://forums.phpfreaks.com/topic/236857-unique-id-by-array_-shift/#findComment-1217687 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 yes i see why my theory is flawed...my appologies Link to comment https://forums.phpfreaks.com/topic/236857-unique-id-by-array_-shift/#findComment-1217690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.