如何在无序PHP数组中找到最低价格(数量)和最高价格(数量)? [重复]

Possible Duplicate:
How to get the highest and lowest value items of an array?

I have an array in PHP which output like this:

Array ( [0] => 180.99 [1] => 140 [2] => 200.45 )

The numbers can be decimals because they are prices.

For example, I want to show that the product has price ranging from 140 to 200 . How can I use that unordered array to find the min, max price within it?

Thank you

Something like using these special functions - min and max - will be helpful, perhaps?

$arr = array(180.99, 140, 200.45);
$min = min($arr);
echo $min; // 140
$max = max($arr);
echo $max; // 200.45

You can use the min and max functions as:

$arr = array(180, 140, 200);
$min = min($arr);
$max = max($arr);

Surprisingly min() & max()

http://php.net/min

http://php.net/max

echo "this price range is between $" . min($array) . " and $" . max($array);

do you mean min() and max()

you can order the array, using sort, and then access the first and last element, of the sorted array.

   $arr = array(180, 140, 200);
   sort($arr);
   echo $arr[0]; //first element
   echo end($arr); //last element

you can also use, min() and max() functions like this,

  $arr = array(180, 140, 200);      
  echo min($arr); //min element
  echo max($arr); //max element
$array = array(180, 140, 200);

echo 'Min: ' . min($array) . "
";
echo 'Max: ' . max($array) . "
";