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 Gitlab

You might also enjoy…

  • Public Relations

    Posted on 16th March 2011.

    Sometimes I wish we lived in a musical. Not not necessarily with all the singing but just with all that general happiness.

  • Redirect to one central domain - htaccess

    Posted on 21st February 2011.

    If you would like to 'redirect' all your users to a central domain (for example if you would like all users to browse your site with the www or you have several parked domains)

Mike Street

Written by Mike Street

Mike is a front-end developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Twitter.