使用in_array PHP检查此数组

I have an $checked array, looks like this:

array(2) {
  [0]=>
  array(1) {
    ["id_kategorii"]=>
    string(1) "2"
  }
  [1]=>
  array(1) {
    ["id_kategorii"]=>
    string(1) "4"
  }
}

$category array in foreach looks like:

array(2) {
  ["id"]=>
  string(2) "14"
  ["nazwa"]=>
  string(3) "123"
}
array(2) {
  ["id"]=>
  string(1) "8"
  ["nazwa"]=>
  string(5) "ajaja"
}
array(2) {
  ["id"]=>
  string(1) "4"
  ["nazwa"]=>
  string(23) "ale nie no kurde w dupe"
}

etc........

But it's not typical array like array('1','2','3'); So I think because of it this doesn't work but I don't know...

And I have PHP code like this:

foreach($categories as $category)
            {
                $final .= '<tr>';

                if( in_array($category['id'], $checked) )
                {
                    $final .= '<td>'.form_checkbox(array('name' => 'categories[]', 'value' => $category['id'], 'checked' => 'checked')).'</td>';
                }
                else
                {
                    $final .= '<td>'.form_checkbox(array('name' => 'categories[]', 'value' => $category['id'])).'</td>';
                }

But always it comes with else, in_array never goes true.

And it should go true for category['id'] when it's 2 and 4.

Why isn't this in_array working properly?

You need to reform the checked array using array_column() function.

$checked = array(array('id_kategorii' => '2'), array('id_kategorii' => '4'));
$new_checked = array_column($checked, 'id_kategorii');
print_r($new_checked);

Then use the $new_checked array in your in_array().