Advertisement
koki2000

Avarge implementation in PHP language

Oct 23rd, 2020
2,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. $magassagok = array(
  2.     'ferfiak' => array(1, 2, 100, 150, 200),
  3.     'nok'     => array(3, 4, 5, 6, 10)
  4. );
  5.  
  6.  
  7. function atlagmagassag($data)
  8. {
  9.     $atlagok = array();
  10.     $osztoszam = 0;
  11.  
  12.     $temp = 0;
  13.     foreach ($data as $nem => $magassag)
  14.     {
  15.         $osztoszam = count($magassag);
  16.         $temp = 0;
  17.  
  18.         foreach($magassag as $index => $value)
  19.         {
  20.             if ($index < $osztoszam )
  21.             {
  22.                 $temp += $value;
  23.             }
  24.             if ($index == ($osztoszam-1) )
  25.             {
  26.                 $atlagok[$nem] = ($temp/$osztoszam);
  27.             }
  28.         }
  29.  
  30.     }
  31.     return $atlagok;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement