Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Exercice 1
- $Tprod = array("Abricot","Cerise","Fraise","Peche");
- $Tvente = array(
- "User1" => array("Abricot" => 20, "Cerise" => 10, "Fraise" => 10),
- "User2" => array("Cerise" => 10, "Abricot" => 20, "Peche" => 30),
- "User3" => array("Cerice" => 5, "Abricot" => 10));
- //(1)
- function constr($Tprod, $Tvente) {
- foreach ($Tvente as $key => $value) {
- $somme = 0;
- foreach($value as $prod => $val)
- $somme += $val;
- $TSAc[$key] = $somme;
- }
- return $TSAc;
- }
- $TSAc = constr($Tprod, $Tvente);
- //(2)
- function calcQteProd($Tvente, $nom) {
- $qte = 0;
- foreach ($Tvente as $key => $value) {
- foreach($value as $prod => $val) {
- if($prod == $nom)
- $qte += $val;
- }
- }
- return $qte;
- }
- //(3)
- $totale = 0;
- foreach ($Tprod as $value)
- $totale += calcQteProd($Tvente, $value);
- foreach ($Tprod as $value) {
- $TPourcent[$value] = (calcQteProd($Tvente, $value) / $totale) * 100;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement