Php 间接修改Guzzle\Service\Resource\Model的重载元素无效
当我试图从数组中删除某个项时,出现此错误。关于SO的其他问题说,这是因为变量实际上不是数组。我也尝试过解决办法。代码如下所示Php 间接修改Guzzle\Service\Resource\Model的重载元素无效,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,当我试图从数组中删除某个项时,出现此错误。关于SO的其他问题说,这是因为变量实际上不是数组。我也尝试过解决办法。代码如下所示 $temp = $tripsAndMatchStrengths['Responses']['userTrip']; foreach ($temp as $key => $trip) { if (condition) { // code } else
$temp = $tripsAndMatchStrengths['Responses']['userTrip'];
foreach ($temp as $key => $trip)
{
if (condition)
{
// code
}
else
{
// Remove this entry from array
unset($temp[$key]);
}
}
// Error is on this line
$tripsAndMatchStrengths['Responses']['userTrip'] = $temp;
为什么不直接在数组上使用?我尝试了
$temp=&$tripsAndMatchStrengths['Responses']['userTrip']代码>。它在另一行unset($temp[$key])上给出了相同的错误
foreach($key=>&$trip)我不知道它是否能解决你的问题,我以前从来没有见过这个错误。@Debflav我刚开始只是用foreach($key=>,$Responses']['userTrip']作为$key=>和$trip)
。我无法解决这个问题,但在我的代码中使用了不同的方法,我不必删除对象。