문제

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.

도움이 되었습니까?

해결책

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

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

Demo

다른 팁

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top