digibucc Posted October 30, 2013 Share Posted October 30, 2013 Ok, I can throw actual code here but it's all rather long, so i am going to give an example: <?php $max = 10; // max runs per exec $arr = array_fill(0, 50, 0); $last = file_get_contents('last.txt'); $n = 0; echo 'left off on '. $last; while ($n < $max) { foreach ($arr as $k => $v) { if ($k > $last) { // do something with the value ($v) $n ++; } } } file_put_contents(last.txt, $k)); ?> <meta http-equiv="refresh" content="3"> this isn't anything i use, but i do something similar when i want to save where i left off in a program to come back to later. that way if the program crashes or i have to close it, i haven't lost my place. this is normally when working with database records. it makes it run incrementally and as i said save it's place to return to. it just feels wrong though, and i'm sure it is. especially the refresh. what is the best way to do this? I would use array_slice instead of if ($k > $last), but that is normally comparing row values from a db, so i can't just arbitrarily slice that. Link to comment https://forums.phpfreaks.com/topic/283435-proper-way-to-save-your-place-looping-an-arraydb/ Share on other sites More sharing options...
Ch0cu3r Posted October 30, 2013 Share Posted October 30, 2013 Sorry I do not understand your question/problem. Could you explain what you are trying to do. Link to comment https://forums.phpfreaks.com/topic/283435-proper-way-to-save-your-place-looping-an-arraydb/#findComment-1456194 Share on other sites More sharing options...
digibucc Posted October 30, 2013 Author Share Posted October 30, 2013 i just rewrote it, does that help? Link to comment https://forums.phpfreaks.com/topic/283435-proper-way-to-save-your-place-looping-an-arraydb/#findComment-1456195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.