在PHP中,我有一个像这样的数组
Array
(
[0] => Array
(
[name] => Printed Chiffon Dress
)
[1] => Array
(
[name] => Printed Dress
)
[2] => Array
(
[name] => Printed Dress
)
[3] => Array
(
[name] => Printed Summer Dress
)
[4] => Array
(
[name] => Printed Summer Dress
)
)
我想将该数组转换为这种格式
Array
(
[0] => Printed Chiffon Dress
[1] => Printed Dress
[2] => Printed Dress
[3] => Printed Summer Dress
[4] => Printed Summer Dress
)
那么有人可以告诉我如何将数组转换为上述格式吗?任何帮助和建议都会非常明显。感谢
答案 0 :(得分:1)
如果您使用的是PHP 5.5及更高版本,则可以使用array_column
:
$new_array = array_column($array, 'name');
如果您根本不需要任何功能,foreach会做得很好,然后将其推入另一个容器中:
$new_array = array();
foreach($array as $value) {
$new_array[] = $value['name'];
}