我正在尝试获取每个字段的值,例如。没有translation
的子数组中的foreach
。可能吗?
Array
(
[0] => Array
(
[group_id] => 11
[group_translation] => Extras
[id] => 21
[operation] => +
[price] => 5
[price_by] => once
[price_type] => fixed
[translation] => Pick up
[price_total] => 5
)
[1] => Array
(
[group_id] => 11
[group_translation] => Extras
[id] => 22
[operation] => +
[price] => 10
[price_by] => once
[price_type] => fixed
[translation] => Drinks
[price_total] => 10
)
)
谢谢!
答案 0 :(得分:0)
当然有可能:
<?php
$data = [
[
'group_id' => 11,
'group_translation' => 'Extras',
'id' => 21,
'operation' => '+',
'price' => 5,
'price_by' => 'once',
'price_type' => 'fixed',
'translation' => 'Pick up',
'price_total]' => 5
],
[
'group_id' => 11,
'group_translation' => 'Extras',
'id' => 22,
'operation' => '+',
'price' => 10,
'price_by' => 'once',
'price_type' => 'fixed',
'translation' => 'Drinks',
'price_total' => 10
]
];
$extract = [];
array_walk($data, function($element) use (&$extract) {
$extract[] = $element['translation'];
});
var_dump($extract);
输出显然是:
array(2) {
[0] =>
string(7) "Pick up"
[1] =>
string(6) "Drinks"
}