php - How to echo text based on highest number in set of variables? -
i interested in echoing specific text based on variable in set of variables, has greatest numeric value. example, if $var1 = 6
, $var2 = 10
, $var3 = 8
, $var4 = 4
i'd echo set of text based on variable has highest numerical number. looking @ website php array reference , saw code:
<?php $age = array("peter"=>"35", "ben"=>"37", "joe"=>"43"); arsort($age); foreach($age $x => $x_value) { echo "key=" . $x . ", value=" . $x_value; echo "<br>"; } ?>
i wondering if there way switch code around sort variables value.
note: variables change throughout due user interaction.
$age = array("peter"=>"35", "ben"=>"37", "joe"=>"43"); arsort($age); reset($age); // not needed here, in general idea $oldest = key($age); if ($oldest == "peter") { echo "pete's boss"; } else { echo "pete's not boss"; }
Comments
Post a Comment