in_array / array_keys : résultats incohérents (casse-tête !)
Bonjour,
Malgré moultes tests et avoir cherché / retourné le problème dans tous les sens, je ne comprends pas les résultats que me retourne PHP pour une bête opération logique (ce qui a le don de m'exaspérer au passage ! :cry:)
Fatigue ? Proche du pont ?
Si quelqu'un peut m'aider sur ce mystérieux et insondable problème... ! D'avance merci.
Code:
1 2 3 4 5 6 7
|
$Infos = json_decode($Quelquechose,true);
if ($Infos==false)
return false;
if (!in_array(array_keys($Infos),array('action','type','id')))
return ' non ! ';
return ' oui ! '; |
Résultat : non !
Code:
1 2 3 4 5 6 7
|
$Infos = json_decode($Quelquechose,true);
if ($Infos==false)
return false;
if (!in_array(array('action','type','id'),array_keys($Infos)))
return ' non ! ';
return ' oui ! '; |
Résultat : non !
Code:
1 2 3 4 5 6 7
|
$Infos = json_decode($Quelquechose,true);
if ($Infos==false)
return false;
if (array_keys($Infos) == array('action','type','id'))
return ' non ! ';
return ' oui ! '; |
(Sachant que la structure du JSON est identique en tout point hein...)
Résultat : oui !
Si je fais un var_dump sur les deux tableaux :
Code:
1 2 3
|
array(3) { [0]=> string(6) "action" [1]=> string(4) "type" [2]=> string(2) "id" }
array(3) { [0]=> string(6) "action" [1]=> string(4) "type" [2]=> string(2) "id" } |
WTF ?! Pourquoi diable le in_array ne me retrouve pas l'existence des valeurs d'un des tableaux dans l'autre ?!
... Pour l'instant je fais du moche et cracra :
Code:
1 2 3 4 5
| if (
!in_array('action',array_keys($Infos)) OR
!in_array('type',array_keys($Infos)) OR
!in_array('id',array_keys($Infos))
) |