0

How can I check if a value is in an array when the array is nested? Seems to be that my attempt is't the right way to do that as it doesn't return a match.

$hash='0ec29d9cdb18f1e11cf0d5f515025350';
if (in_array($hash, $array)) { echo "Found it!"; }

var_dump($array);

array(2) { [0]=> array(1) {
["hash"]=> string(32) "0ec29d9cdb18f1e11cf0d5f515025350" } 
[1]=> array(1) {
["hash"]=> string(32) "5082227aa45743157ae557ca49b56d36" }
} 
2
  • @Jay Blanchard Ok, but I'm a bloody beginner and I can't still figure it out. Commented Jun 16, 2017 at 16:44
  • $foo=array_column($array, 'hash');if (in_array($hash, $foo)) { echo "Found it!"; I solved it this way. Commented Jun 16, 2017 at 17:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.