xenium
asked on
How to extract the values from a nested array into another array
I want to extract a column from a nested array, example:
Array
(
[0] => Array
(
[id] => 11
[order_id] => 6127
)
[1] => Array
(
[id] => 12
[order_id] => 6123
)
)
This is what I need:
$results = array()
$results(6127, 6123)
I'd like to do this concisely eg with an array_map or similar
Copied from here as I have a similar question and it was not answered here:
https://stackoverflow.com/questions/8873146/how-to-extract-the-values-from-a-nested-array-into-another-array
Array
(
[0] => Array
(
[id] => 11
[order_id] => 6127
)
[1] => Array
(
[id] => 12
[order_id] => 6123
)
)
This is what I need:
$results = array()
$results(6127, 6123)
I'd like to do this concisely eg with an array_map or similar
Copied from here as I have a similar question and it was not answered here:
https://stackoverflow.com/questions/8873146/how-to-extract-the-values-from-a-nested-array-into-another-array
ASKER
Although answered, is it possible to do the same but referencing by column number instead of the name 'order_id' ?
ASKER
The following is simpler, but only seems to work naming the column:
$arr_order_id = array_column($rows, 'order_id');
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window