Limit Items (e.g. News posts)

If you would like to limit the amount of items coming out of an array (for example the first 5 news items), then before your loop (e.g. while), specify your start and finish points

$A = array_slice($A, START, END);
while $A {

For example, if you did want to only pull out the first 5 news items in an array, you would:

$news_items = array_slice($news_items, 0, 5);
while $news_items {

View this post on Github

You might also enjoy…

Mike Street

Written by Mike Street

Mike is a CTO and Lead Developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Mastodon.