Utilisez array_key_exists !
<?php | |
$a = ['AB' => 12, 'CB' => 34]; | |
echo "Cas nominal : La clé est présente dans le tableau".PHP_EOL; | |
echo (int)array_key_exists('AB', $a).PHP_EOL; | |
echo (int)isset($a['AB']).PHP_EOL; | |
echo (int)!empty($a['AB']).PHP_EOL; | |
echo "Cas nominal : La clé n'est pas présente dans le tableau".PHP_EOL; | |
echo (int)array_key_exists('YZ', $a).PHP_EOL; | |
echo (int)isset($a['YZ']).PHP_EOL; | |
echo (int)!empty($a['YZ']).PHP_EOL; | |
echo "Cas limite : la clé est présente mais vaut 0".PHP_EOL; | |
$b = ['EF' => 0]; | |
echo (int)array_key_exists('EF', $b).PHP_EOL; | |
echo (int)isset($b['EF']).PHP_EOL; | |
echo (int)!empty($b['EF']).PHP_EOL; | |
echo "Cas limite : la clé est présente mais vaut null".PHP_EOL; | |
$c = ['GH' => null]; | |
echo (int)array_key_exists('GH', $c).PHP_EOL; | |
echo (int)isset($c['GH']).PHP_EOL; | |
echo (int)!empty($c['GH']).PHP_EOL; | |
echo "Cas limite : Le tableau n'existe pas".PHP_EOL; | |
echo (int)array_key_exists('IJ', $d).PHP_EOL; | |
echo (int)isset($d['IJ']).PHP_EOL; | |
echo (int)!empty($d['IJ']).PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment