dose Posted November 1, 2009 Share Posted November 1, 2009 im still very newb at php but what im seeking might be real simple for some to help with. im using preg_match_all to fill an array. can have a infinate ammount of returns. How would i split that array into say groups of 4 and be able to display them all? Quote Link to comment https://forums.phpfreaks.com/topic/179794-solved-splitting-array/ Share on other sites More sharing options...
hackerkts Posted November 1, 2009 Share Posted November 1, 2009 What do you mean by groups of 4? Quote Link to comment https://forums.phpfreaks.com/topic/179794-solved-splitting-array/#findComment-948572 Share on other sites More sharing options...
dose Posted November 1, 2009 Author Share Posted November 1, 2009 ok say i have $a which contains 1 2 3 4 5 6 7 8 9 10 11 12 13 14 etc i want to store 1-5 into its own array then 6-10 in another array and so on Quote Link to comment https://forums.phpfreaks.com/topic/179794-solved-splitting-array/#findComment-948578 Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 <?php $a = '1 2 3 4 5 6 7 8 9 10 11 12 13 14'; $split = explode(' ', $a); for($i = 0;$i < count($split);$i += 5) $arrays[] = array_slice($split, $i, 5); then $arrays will contain all the arrays that you want. So $arrays[0] would be an array containing the numbers 1-5, etc.. Quote Link to comment https://forums.phpfreaks.com/topic/179794-solved-splitting-array/#findComment-948586 Share on other sites More sharing options...
dose Posted November 1, 2009 Author Share Posted November 1, 2009 thanks did jus what i wanted Quote Link to comment https://forums.phpfreaks.com/topic/179794-solved-splitting-array/#findComment-948588 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.