我有一个多维数组,其中一些值来自 foreach,我需要将这些值插入到数组中,但此时我的结果是这样的,不知道为什么:
Array
(
[0] => Array
(
[title] => MySecure
)
[1] => Array
(
[productTitle] => My New Product
)
[2] => Array
(
[title] => My Second Company
)
[3] => Array
(
[productTitle] => Another Product
)
[4] => Array
(
[productTitle] => Away Product
)
)
这是错误的,我需要的是:
Array
(
[0] => Array
(
[title] => MySecure
[productTitle] => My New Product
)
[2] => Array
(
[title] => My Second Company
[productTitle] => Another Product
[productTitle] => Away Product
)
)
这就是我所做的:
$companies[] = [
'title' => $getCompanie->getTitle()
];
然后是里面的产品:
$companies[] = [
'productTitle' => $getProduct->getTitle(),
];
所以我假设我使用了错误的数组调用,不确定 array_push?
慕无忌1623718
慕妹3146593