Reputation: 119
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
)
)
)
I want its result
Attributes 2, Attributes 3
Attributes 1, Attributes 3
Upvotes: 1
Views: 78
Reputation: 9583
By using foreach
and array_column
you can did this thing. let array as $arr
and use implode()
for comma separated output.
Check this online: https://3v4l.org/Bdgh5
foreach($arr as $value){
echo implode(", ", array_column($value, 'name'));
}
Let me know is it okey or not?
Upvotes: 1
Reputation: 499
It is another way, by using only 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'];
}
}
Upvotes: 0