0

I have a big array which i need to display the latest 10 items in it only. what is the best php code to do that?

thanks

1
  • define latest. as in from 0 to 9? Commented Apr 30, 2010 at 15:02

2 Answers 2

5

Use array_slice

$printing = array_slice($array, -10);

print_r($printing); //or however you want to print it.
Sign up to request clarification or add additional context in comments.

Comments

1
foreach( array_slice( $array, -10 ) as $k => $v ) {
    echo $v;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.