49
Array
(
    [university] => 57
    [iit] => 57
    [jee] => 44
    [application] => 28
    [study] => 26
    [college] => 23
    [exam] => 19
    [colleges] => 19
    [view] => 19
    [amp] => 18
)

How can I get an array with the first 5 elements?

0

2 Answers 2

120

Use array_slice() function:

$newArray = array_slice($originalArray, 0, 5, true);
Sign up to request clarification or add additional context in comments.

Comments

5

If you need the first 5 elements

before the array_slice(). Insert a letter 'r' to the second place for reverse order: krsort(), arsort().

1 Comment

Yep, but maybe he means top 5.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.