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