Array
(
[0] => Array
(
[0] => Array
(
[name] => Attributes 2
)
[1] => Array
(
[name] => Attributes 3
)
)
[1] => Array
(
[0] => Array
(
[name] => Attributes 1
)
[1] => Array
(
[name] => Attributes 3
)
)
)
我想要它的结果
属性2、属性 3
属性1、属性 3
通过使用foreach
和array_column
你可以做这件事。 让数组作为$arr
并使用implode()
进行逗号分隔的输出。
在线查看: https://3v4l.org/Bdgh5
foreach($arr as $value){
echo implode(", ", array_column($value, 'name'));
}
让我知道是不是好?
这是另一种方式,仅使用 foreach
$arr = array (
0 => array (
0 => array ( "name" => "Attributes 2"),
1 => array ( "name" => "Attributes 3")
),
1 => array (
0 => array ( "name" => "Attributes 1"),
1 => array ( "name" => "Attributes 3")
)
);
foreach($arr as $value){
foreach ($value as $key ) {
echo $key['name'];
}
}