I have an array that looks like the following when var_dump:
array(3) { [0]=> array(3) { ["id"]=> string(1) "3" ["category"]=> string(5) "staff" ["num_posts"]=> string(1) "1" } [1]=> array(3) { ["id"]=> string(1) "1" ["category"]=> string(7) "general" ["num_posts"]=> string(1) "4" } [2]=> array(3) { ["id"]=> string(1) "2" ["category"]=> string(6) "events" ["num_posts"]=> string(1) "1" } }
I need to echo a value if the array does not contain the following string: ‘hello’
How is this possible, I have tried using in_array, but unsuccessfully. Help appreciated.
Advertisement
Answer
foreach ($array as $subarray) { if(!in_array('hello', $subarray)) { echo 'echo the value'; } }