note 100899 modified in function.min by danbrown
| From: | danbrown@php.net | Date: | Sat, 13 Nov 2010 23:17:46 +0000 |
| Subject: | note 100899 modified in function.min by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174009@lists.php.net to get a copy of this message | ||
A condensed version (and possible application) of returning an array of array keys containing the
same minimum value:
<?php
// data
$min_keys = array();
$player_score_totals = array(
'player1' => 300,
'player2' => 301,
'player3' => 302,
'player4' => 301,
...
);
// search for array keys with min() value
foreach($player_score_totals as $playerid => $score)
if($score == min($player_score_totals)) array_push($min_keys, $playerid);
print_r($min_keys);
?>
--was--
A condensed version (and possible application) of returning an array of array keys containing the
same minimum value:
// data
$min_keys = array();
$player_score_totals = array(
'player1' => 300,
'player2' => 301,
'player3' => 302,
'player4' => 301,
...
);
// search for array keys with min() value
foreach($player_score_totals as $playerid => $score)
if($score == min($player_score_totals)) array_push($min_keys, $playerid);
print_r($min_keys);
http://php.net/manual/en/function.min.php