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); Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 16, 2012 Share Posted November 16, 2012 (edited) 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); Edited November 16, 2012 by Psycho Quote Link to comment 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 ... Quote Link to comment 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.