Arrays

Hello, i was seeing if anyone could help me with a function i am having an issue writing.
I have to put the first three values into the array, sort it and return the value in the array given by the 4th parameter, and if the 4th parameter is 2 then return the 2nd value of the array.
My function is-
function sortArray($parameter1,$parameter2,$parameter3,$parameter4) {

 //Function and array with four parameters 

 if ($parameter4 =2) 
      return result;
      //returns result with parameter 
       rsort($sortArray); 

I know this is not correct,I am not too familiar with arrays better yet PHP code at all.

Show us how you have your array setup that way people will be able to help you out better.

You could pass the array into the function to make it easier
Once in it you just want to use the number to pull out the specific key in the array
The - 1 is because the array will start the key at 0
Hope this helps
[php]
$result = sortMyArray(array($param1, $param2, $param3), 2);

function sortMyArray($params = array(), $number) {
$key = ($number > 0 && $number <= count($params)) ? $number - 1 : 0;
asort($params);
return array_key_exists($key, $params) ? $params[$key] : false;
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service