Manixat Posted November 16, 2012 Share Posted November 16, 2012 How is this an infinite loop ? <?php $a = array("a","b","c","d","e","f"); $b = array(); for($i=0;$i<=count($a);$i+2){ $b[$a[$i]]=$a[$i+1]; } print_r($B); Link to comment https://forums.phpfreaks.com/topic/270808-infinite-loop/ Share on other sites More sharing options...
Psycho Posted November 16, 2012 Share Posted November 16, 2012 Because $i + 2 does not increment $i by 2. It only Adds $i and 2 and leaves the result on the stack. I.e. it doesn't do anything. Use $i += 2 $a = array("a","b","c","d","e","f"); $b = array(); for($i=0;$i<=count($a);$i+=2) { $b[$a[$i]] = $a[$i+1]; } print_r($B); Link to comment https://forums.phpfreaks.com/topic/270808-infinite-loop/#findComment-1393094 Share on other sites More sharing options...
Manixat Posted November 16, 2012 Author Share Posted November 16, 2012 And I call myself a php programmer ... Link to comment https://forums.phpfreaks.com/topic/270808-infinite-loop/#findComment-1393097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.