1

I have an array containing only numbers, i want to sort them using asort so it shows the lowest number first.

but now i have the array sorted, how do i make it show only the first result?

For instance, this is my array:

Array ( [0] => 399 [1] => 349  ) 

and after asort:

Array ( [1] => 349 [0] => 399 ) 

how do i echo only the first result after i asort as i cant just use Array[1] because it might not always be [1] etc..

Sorry if this is a dumb question, but its late and my brain has ceased to function correctly lol.

2 Answers 2

2

Just use sort() which won't maintain key association.

$array = array(399, 349);
sort($array);
print_r($array);
// Array ( [0] => 349 [1] => 399 )

Demo

0
2

Something like this: echo current($array); or $first=current($array);

No need to reset() because the array is automatically reset after being sorted.

0

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.