note 81531 added to function.max

From: Date: Mon, 03 Mar 2008 07:11:27 +0000
Subject: note 81531 added to function.max
Groups: php.notes 
Request: Send a blank email to php-notes+get-136680@lists.php.net to get a copy of this message
mick at wireframe dot com's solution to finding the key for the highest value didn't work for me, so I wrote one myself: <?php function max_key($array) { foreach ($array as $key => $val) { if ($val == max($array)) return $key; } } $array = array(1, 2, 5, 7, 4); echo max($array); // 7 echo max_key($array); // 3 ?> of course this also works with associative arrays, but it will only return a single result! ---- Server IP: 69.147.83.197 Probable Submitter: 84.177.183.216 ---- Manual Page -- http://www.php.net/manual/en/function.max.php Edit -- https://master.php.net/note/edit/81531 Del: integrated -- https://master.php.net/note/delete/81531/integrated Del: useless -- https://master.php.net/note/delete/81531/useless Del: bad code -- https://master.php.net/note/delete/81531/bad+code Del: spam -- https://master.php.net/note/delete/81531/spam Del: non-english -- https://master.php.net/note/delete/81531/non-english Del: in docs -- https://master.php.net/note/delete/81531/in+docs Del: other reasons-- https://master.php.net/note/delete/81531 Reject -- https://master.php.net/note/reject/81531 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136680) next »