Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 间接修改Guzzle\Service\Resource\Model的重载元素无效_Php_Arrays_Multidimensional Array - Fatal编程技术网

Php 间接修改Guzzle\Service\Resource\Model的重载元素无效

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

当我试图从数组中删除某个项时,出现此错误。关于SO的其他问题说,这是因为变量实际上不是数组。我也尝试过解决办法。代码如下所示

    $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)
。我无法解决这个问题,但在我的代码中使用了不同的方法,我不必删除对象。