Advertisement
touhid_xml

Finding the highest number from an array in PHP

Apr 1st, 2015
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <?php
  2. /**$goru = 2000;
  3. $chagol = 3000;
  4. $hash = 4000;
  5. $murgi = 5000;
  6. $biral = 6000;**/
  7.  
  8. $animals = array(
  9.     "goru" => 2000,
  10.     "chagol" => 3000,
  11.     "hash" => 4000,
  12.     "murgi" =>  5000,
  13.     "biral" => 6000
  14. );
  15. $max = max($animals); //maximum value
  16. foreach($animals as $key => $value){ //loop the array to find maximum value with key
  17.     if($value == $max){
  18.     echo "Maximum amount animal is {$key}: {$value}\n";
  19.         break; //if found the maximum value with key exit from the loop by break keyword.
  20.     }
  21. }
  22.  
  23.  
  24. /*************************
  25.  * created by Touhid
  26.  * touhid@rafusoft.com
  27.  ************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement