PHP中的for循环和附加到数组

PHP中的for循环和附加到数组,php,doctrine,Php,Doctrine,我有以下代码: $items = array(); foreach($following as $storeOwner) { array_push($items, $productRepository->mostRecentItem($storeOwner->getId(), 5)); } 我正在尝试附加 $productRepository->mostRecentItem($storeOwner->getId(), 5) 到$items。我该怎么做?为什

我有以下代码:

$items = array();

foreach($following as $storeOwner)
{
    array_push($items, $productRepository->mostRecentItem($storeOwner->getId(), 5));
}
我正在尝试附加

 $productRepository->mostRecentItem($storeOwner->getId(), 5)

$items
。我该怎么做?为什么上面的代码不起作用?

var\u dump可以使用不同的对象并返回值,以确保包含您认为应该包含的内容。代码看起来“正确”,因此可能是对象和值不正确。

尝试以下方法:

$items = array();

foreach($following as $storeOwner)
{
    $items[] = $productRepository->mostRecentItem($storeOwner->getId(), 5);
}

另外,请看一下mostRecentItem方法的结果

您调试过$productRepository->mostRecentItem($storeOwner->getId(),5)返回什么吗?逻辑正确,语法正确,值可能不正确。您的方法返回什么如果它是另一个数组,array\u merge将执行任务$productRepository->mostRecentItem($storeOwner->getId(),5)必须返回字符串值。结果如何?什么不起作用?