1

I have an array in the form of:

array(2) { [0]=> array(1) { ["positionID"]=> int(100) } [1]=> array(1) { ["positionID"]=> int(102) } }

I want to check 100 or 102 is contained in the array.

I tried code below, but it doesn't work. Can I get some help?

var_dump(in_array(102, $myArray));
Antony Jack
  • 480
  • 2
  • 16
kevin
  • 173
  • 2
  • 10

2 Answers2

0

As @mario pointed out, you're going to want to use something like array_column:

var_dump(in_array(102, array_column($myArray, 'positionID")));

zeterain
  • 1,140
  • 1
  • 10
  • 15
0

Use

in_array(102, array_column($myArray, 'positionID'));

in_array checks the direct values of the array. So doing in_array(102, $myArray);, you are checking an integer (102) against the values of the array which are arrays.

Prince Dorcis
  • 955
  • 7
  • 7