数组中两个值之间的最大/最大差异

So, I need to find out the highest possible difference between any two random values of an indexed array and I am not sure if my answer is correct, coz you know it's way too simple for the weight of this question:

function($array)
{
 asort($array); 
 $diff = $array(sizeof($array) - 1) - $array(0);
 return $diff; 
}

I am sure this is correct, then again I always have my doubts!

You are right that the largest difference you will find is between the maximum value and the minimum value. However, you could achieve this more efficiently (O(N) instead of O(N log N)) by simply scanning the array to find the min and max values without sorting.

Just to wrap your head around the logic, here is a manual way of doing this:

$myarray = array(
  'this' => 2, 
  'that' => 14, 
  'them' => -5, 
  'other' => 200, 
  'nothing' => 42, 
  'somethingelse' => 1, 
  'you' => 10, 
  'me' => 30);

foreach ($myarray as $key => $value) {
  if (!isset ($min) || $value < $min) { $min = $value; }
  if (!isset ($max) || $value > $max) { $max = $value; }
}

$diff = $max - $min;
echo $diff;