0

I have the following array:

Array
(
    [0] => Array
        (
            [video_id] => 161162806
        )

    [1] => Array
        (
            [video_id] => 161736574
        )

    [2] => Array
        (
            [video_id] => 156382678
        )    
)

I try to find a value, but even though it's in the array it doesn't find it.

if(in_array("161162806", $safe, true)) {      
 echo "approved video";
  } else { 
  echo "non-approved video";
 }

What am I doing wrong?

0

2 Answers 2

2

It is because you have arrays in array (multidimensional array).

You have to loop over :

foreach($safe as $s) {

if(in_array("161162806", $s)) {      
 echo "approved video";
  } else { 
  echo "non-approved video";
 }
}

PS : Remove true param if you want to assimilate integers and strings :

123 or "123"

Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome. Please, valid an answer (mine or DevDonkey's)
0

you have declared a 'strict' check on in_array.

Because of this it will check the type as well. Seeing as your search parameter is a string, it wont match the integer in the array.

try this (when you've sorted the below mentioned issue):

if(in_array("161162806", $safe)) {      
   echo "approved video";
} else { 
   echo "non-approved video";
}

but you have separate arrays in the one your'e checking. in_array will only check the direct values of the array provided. Have a look at this question for a possible solution to that part of the problem. (Or Delphines answer)

1 Comment

Thank you for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.