1

Here is the one value that can not determine PHP in_array function. I think this is issue with value but why ? I am stuck.

"ZQjEa8EsL2kdHr2xD2jkoWj678FWsLL2Ng1tFjDV/Rgkt0CLiE4f+lvlYrdDjvq2"

PHP Example

<?php
    $id = "ZQjEa8EsL2kdHr2xD2jkoWj678FWsLL2Ng1tFjDV/Rgkt0CLiE4f+lvlYrdDjvq2";
    $array['selected_options']['12251_12754_3'][0] = 0;

    var_dump(in_array($id, $array['selected_options']['12251_12754_3']));
?>

Output

true

Try it online!

Question : Anybody knows why this happen or what I do instead ?

Answers much appriciated !

3
  • 1
    that's what happens when you compare in in_array loosely Commented Jul 29, 2019 at 7:39
  • heck you can even do var_dump(in_array(null, $array['selected_options']['12251_12754_3'])); and it'll still yield true Commented Jul 29, 2019 at 7:40
  • You are searching a string variable in int array declare array as string or id as int try again Commented Jul 29, 2019 at 7:41

1 Answer 1

2

Searches for needle in haystack using loose comparison unless strict is set.

Append the third argument with true to get the result you need.

var_dump(in_array($id, $array['selected_options']['12251_12754_3'], true));

See documentation.

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

1 Comment

Isn't that gonna always throw false ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.