Quantcast
Channel: User easement - Stack Overflow
Viewing all articles
Browse latest Browse all 45

Answer by easement for PHP: How can I split a foreach-loop into 3 parts?

$
0
0

I'm not surer that this will work with your ordering, but array_chunk, https://secure.php.net/manual/en/function.array-chunk.php, may do what you want.

This way you don't have to deal with the sharing a common multiple.

If ordering is an issue, there is a comment on the array_chunk page which has some code that does an array_chunk_vertical. One of these two methods should get you what you need.

Something like this untested code below:

// Each group will be in it's own section array. $sections = array_chunk($posts, 2);


Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>