ollie007 Posted June 8, 2009 Share Posted June 8, 2009 array(1,2,3,4); array[0]; array[1]; array[2]; array[3]; how do i grab the odd or even position of those arrays? Quote Link to comment Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 Do you just want them in 2 new arrays?? If so... <?php $numbers = array(1, 2, 3, 4, 5, 6, 7, ; foreach($numbers as $number){ if($number % 2) { $odd[] = $number; } else { $even[] = $number; } } Quote Link to comment Share on other sites More sharing options...
ollie007 Posted June 8, 2009 Author Share Posted June 8, 2009 cool !!! ty Quote Link to comment Share on other sites More sharing options...
ollie007 Posted June 8, 2009 Author Share Posted June 8, 2009 actually i need the position number rather than the value number?? array(10, 40, 99, 2, 66); i need array[1] array[3] etc or array[2] array[4] Quote Link to comment Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 like this?? <?php $numbers = array(10, 21, 32, 46, 57, 68, 79, 80); foreach($numbers as $number =>){ if($number % 2) { $odd[] = $number; } else { $even[] = $number; } } Quote Link to comment Share on other sites More sharing options...
ollie007 Posted June 8, 2009 Author Share Posted June 8, 2009 i give it a shot and see if it blows up anything LOL So i only need the "=>" ? Quote Link to comment Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 yup Quote Link to comment Share on other sites More sharing options...
ollie007 Posted June 8, 2009 Author Share Posted June 8, 2009 thanks a lot working nicely 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.