Advertisement
amine99

Untitled

Sep 10th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2.     //Exercice 1
  3.     $Tprod = array("Abricot","Cerise","Fraise","Peche");
  4.     $Tvente = array(
  5.         "User1" => array("Abricot" => 20, "Cerise" => 10, "Fraise" => 10),
  6.         "User2" => array("Cerise" => 10, "Abricot" => 20, "Peche" => 30),
  7.         "User3" => array("Cerice" => 5, "Abricot" => 10));
  8.    
  9.     //(1)
  10.     function constr($Tprod, $Tvente) {
  11.         foreach ($Tvente as $key => $value) {
  12.             $somme = 0;
  13.             foreach($value as $prod => $val)
  14.                 $somme += $val;
  15.             $TSAc[$key] = $somme;
  16.         }
  17.         return $TSAc;
  18.     }
  19.     $TSAc = constr($Tprod, $Tvente);
  20.     //(2)
  21.     function calcQteProd($Tvente, $nom) {
  22.         $qte = 0;
  23.         foreach ($Tvente as $key => $value) {
  24.             foreach($value as $prod => $val) {
  25.                 if($prod == $nom)
  26.                     $qte += $val;
  27.             }
  28.         }
  29.         return $qte;
  30.     }
  31.     //(3)
  32.     $totale = 0;
  33.     foreach ($Tprod as $value)
  34.         $totale += calcQteProd($Tvente, $value);
  35.     foreach ($Tprod as $value) {
  36.         $TPourcent[$value] = (calcQteProd($Tvente, $value) / $totale) * 100;
  37.     }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement