I've decoded my JSON string and now I want to use the in_array() function in PHP to check if one of the ID numbers is present in the array (number 5 to be exact).
Array:
Array ( [0] => Array ( [id] => 5 ) [1] => Array ( [id] => 4 [children] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [0] => Array ( [id] => 7 [children] => Array ( [0] => Array ( [id] => 10 ) ) ) ) ) ) ) [2] => Array ( [id] => 3 [children] => Array ( [0] => Array ( [id] => 6 [children] => Array ( [0] => Array ( [id] => 8 ) ) ) [1] => Array ( [id] => 9 ) ) ) )
My code (that's failing):
if (in_array(5, $array)) {
echo "i'm in the array!";
}
or
if (in_array('5', $array)) {
echo "i'm in the array!";
}
This seems like a simple problem - am I blind...
`.
– Crackertastic May 19 '14 at 15:25– ABOO May 19 '14 at 15:27