duanbairan4235 2019-02-10 22:28
浏览 41
已采纳

Foreach在功能上

I got a question that hopefully is easy to answer.

In the function below the part "foreach($daten as $row)" is ignored in the second turn. Can somebody tell me, why the function acts that way?

I already tried to delete the "break"... no success.

function verweis_show($string,$art,$daten){


$ausgang = preg_split("/\[-\[(.*?)\/(.*?)\/(.*?)\]-\]/", $string,0,PREG_SPLIT_DELIM_CAPTURE);

$n = 0;

foreach($ausgang as $teil)
{
    $n++;

    if($n == 1)
    {
        $ergebnis .= $teil;

    }
    elseif($n == 2)
    {
        $stat_id = $teil;

    }
    elseif($n == 3)
    {
        $rel_id = $teil;

        if ($art != "old")
        {
            $z = 0;

            // wird im zweiten durchlauf seltsamerweise nicht noch einmal durchlaufen
            foreach($daten as $row) 
            { 
                $z++;

                if ($row['id'] == $stat_id)
                {
                    $rel_id = $z; 
                    break;
                }

            }
        }
    }
    elseif($n == 4)
    {
        $ergebnis .= "<div contenteditable='false' id='text_$stat_id' class='$teil' tabindex='-1'>$rel_id</div>";
        $n = 0;
    }
}

return $ergebnis;    

}

  • 写回答

1条回答 默认 最新

  • duanqin9631 2019-02-10 22:41
    关注

    Foreach requires that it either has an array, or an object that has the traversable interface implemented, which PDOStatement probably does not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大