$items = array(
1 => [
"id" => 5
],
3 => [
"id" => 6
],
4 => [
"id" => 7
],
);
var_dump(array_column($items,"id"));
result,
array (size=3)
0 => int 5
1 => int 6
2 => int 7
But how can I keep the key of $items
so I can get this below?
array (size=3)
1 => int 5
3 => int 6
4 => int 7
See if this could help
array_filter(array_combine(array_keys($items), array_column($items, 'id')));