-
-
Save julp/3d04e148c4d0dd8db607d3a9207a28e7 to your computer and use it in GitHub Desktop.
[OC] if { } else { } vs switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const FDP = [ | |
'France' => [ | |
250 => 4.95, | |
500 => 6.35, | |
750 => 7.25, | |
1000 => 7.95, | |
2000 => 8.95, | |
5000 => 13.75, | |
10000 => 20.05, | |
], | |
'Europe' => [ | |
500 => 12.55, | |
1000 => 15.50, | |
2000 => 17.55, | |
5000 => 22.45, | |
10000 => 37.00, | |
], | |
'Reste du monde' => [ | |
500 => 24.85, | |
1000 => 27.65, | |
2000 => 38, | |
5000 => 55.65, | |
10000 => 105.30, | |
], | |
]; | |
session_start(); | |
if (!array_key_exists('informationDelivery', $_SESSION)) { | |
// erreur : la session n'est pas initialisée comme attendue | |
} else if (!array_key_exists($_SESSION['informationDelivery'], FDP)) { | |
// erreur : zone inconnue | |
} else { | |
$match = NULL; | |
foreach (FDP[$_SESSION['informationDelivery']] as $poids => $prix) { | |
if ($totalMass < $poids) { | |
$match = $prix; | |
break; | |
} | |
} | |
if (is_null($match)) { | |
// erreur : le poids excède le maximum | |
} else { | |
echo 'Les ports sont de : ', $match; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment