note 76199 modified in function.max by danbrown
| From: | danbrown@php.net | Date: | Tue, 22 Mar 2011 14:01:01 +0000 |
| Subject: | note 76199 modified in function.max by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178089@lists.php.net to get a copy of this message | ||
Matlab users and others may feel lonely without the double argument output from min and max
functions.
To have the INDEX of the highest value in an array, as well as the value itself, use the following,
or a derivative:
<?php
function doublemax($mylist){
$maxvalue=max($mylist);
while(list($key,$value)=each($mylist)){
if($value==$maxvalue)$maxindex=$key;
}
return array("m"=>$maxvalue,"i"=>$maxindex);
}
?>
--was--
Matlab users and others may feel lonely without the double argument output from min and max
functions.
To have the INDEX of the highest value in an array, as well as the value itself, use the following,
or a derivative:
<?
function doublemax($mylist){
$maxvalue=max($mylist);
while(list($key,$value)=each($mylist)){
if($value==$maxvalue)$maxindex=$key;
}
return array("m"=>$maxvalue,"i"=>$maxindex);
}
?>
http://php.net/manual/en/function.max.php