Zmeuru Posted July 8, 2009 Share Posted July 8, 2009 Hy there.. i need to make a loop that will run trough an array and if the loop is not over.. the array parsing should go on. But i'm stuck and i need some help. Here is a snippet if anyone is kind enough to take a look. Btw... i'm no php guru, still learning, Thanks! function generate($var) { $num = array("0","9","7","5","3","1","1","6","4","2"); $afd['zorg'] = $var; $afd['p'] = $afd['zorg']{11}; $afd['nct'] = $afd['zorg']{12}; $afd['nrv'] = $afd['zorg']{0}; $afd['mid'] = $afd['zorg']{1}.$afd['zorg']{2}.$afd['zorg']{3}.$afd['zorg']{4}.$afd['zorg']{5}.$afd['zorg']{6}.$afd['zorg']{7}.$afd['zorg']{8}.$afd['zorg']{9}.$afd['zorg']{10}; $key = $afd['nct']; $a = $afd['p']; for ($i=0;$i<=9;$i++) { $mode = next($num); echo "<br>****Num = :$mode<br>"; if($mode==$key) { echo "<br>*Match Found num:$mode - key:$key"; if ($mode == 2) { $mode = reset($num); $a = $a + 1; } break(1); } } for($i=0;$i<10;$i++) { echo "<br>*Magic number :".$afd['nrv'].$afd['mid'].$a.$mode."*<br>"; $mode = next($num); $a = $a+1; if($a == 10) { $a = 0; } } } It is hard for me to explain the problem, but.. i will try to... If i start with this number: 2555555555551 the output will be : 2555555555551 2555555555561 2555555555576 2555555555584 2555555555592 255555555550 255555555551 255555555552 255555555553 255555555554 My problem is that i don't know how to make the array go over again even if it reached the end. Thanks for your patiance!!! Quote Link to comment https://forums.phpfreaks.com/topic/165145-array-script/ Share on other sites More sharing options...
ignace Posted July 8, 2009 Share Posted July 8, 2009 $loops = 2; for ($i = 0; $i < $loops; ++$i) { $sizeOf = sizeof($array); for ($j = 0; $j < $sizeOf; ++$j) { // ..logic.. } } increase $loops if you need to loop over more or use some algorithm to decide how many times it needs to loop over the array Quote Link to comment https://forums.phpfreaks.com/topic/165145-array-script/#findComment-870862 Share on other sites More sharing options...
sasa Posted July 8, 2009 Share Posted July 8, 2009 look <?php function my_next(&$array){ $a = array_shift($array); array_push($array, $a); return $a; } $test = array('a', 'b', 'c'); $i = 0; while ($i++ < 10){ echo my_next($test); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165145-array-script/#findComment-870865 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.