I am using php 7.1
and have the following array:
However, I would simply like to have the following array:
array(3808, 3807, 3806, 3805)
Any suggestions how to convert it to array?
Appreciate your replies!
I am using php 7.1
and have the following array:
However, I would simply like to have the following array:
array(3808, 3807, 3806, 3805)
Any suggestions how to convert it to array?
Appreciate your replies!
array_column()
function will help:
$ids = array_column($records, 'ID');
print_r($ids);
Will output just array of ID's.
Check docs for it Docs
Convert the Object to an Array and use array_column to return an array of values from a specific key.
$a = (object) [
0 => [ 'ID' => 3808],
1 => [ 'ID' => 3807],
2 => [ 'ID' => 3806],
3 => [ 'ID' => 3805],
];
$b = array_column((array)$a, 'ID');
// $b = [3808,3807,3806,3805]
Note: (array)$a
enforces Array conversion. Conversely, (object)$a
will convert an Array to a stdClass Object.