首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Php错误通知:未定义的偏移量:255715

Php错误通知:未定义的偏移量:255715
EN

Stack Overflow用户
提问于 2017-09-07 15:50:14
回答 1查看 186关注 0票数 0

您好,我正在处理一个symfony2项目,当我试图创建关联数组时,这个问题发生了=>注意:未定义的偏移量:25715

代码编辑器警告我错误来自于创建关联数组$Tableau_comptes_dependants这里是代码

代码语言:javascript
复制
foreach ($tableau_compte_fictifs as $tableau_compte_fictif) {
    $Tableau_id_compte_fictifs[] = $tableau_compte_fictif["id"];
}// this array content two value 25715 and 31170                      

foreach ($Tableau_id_compte_fictifs as $Tableau_id_compte_fictif) {

       $Mes_comptes_reels_dependants = $mes_comptesRepo-
           >all_client_compte_dependant($Tableau_id_compte_fictif);

    if (count($Mes_comptes_reels_dependants) > 0) {

    foreach ($Mes_comptes_reels_dependants as 
                $Mes_comptes_reels_dependant) 
    {
      if (!in_array($Mes_comptes_reels_dependant,
                $Tableau_comptes_dependants[$Tableau_id_compte_fictif]))
      {
                $Tableau_comptes_dependants[$Tableau_id_compte_fictif[] =
                    $Mes_comptes_reels_dependant;
      }
    }
}
}
return new JsonResponse(
    array(
        'code' => 200,
        'result' => true,
        'comptes' => $Tableau_id_compte_fictifs,
    )
);

请让我知道我做错了什么

EN

回答 1

Stack Overflow用户

发布于 2017-09-07 16:10:14

通知是通过调用in_array生成的

代码语言:javascript
复制
if (!in_array($Mes_comptes_reels_dependant,
                $Tableau_comptes_dependants[$Tableau_id_compte_fictif]))

您尝试在一个不存在的索引25715上访问数组,因为这是您在方括号中传递的变量的值。

在访问索引之前,您应该首先检查isset是否存在索引。

也就是说,如果你遇到这样的问题,我认为你的代码有一个设计缺陷。你应该尝试重构它,或者和你的同事讨论如何简化它。我必须承认,虽然我可以,但我不会尝试为您解决这个问题,因为您的变量名基本上是不可读的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46090841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档