您好,我正在处理一个symfony2项目,当我试图创建关联数组时,这个问题发生了=>注意:未定义的偏移量:25715
代码编辑器警告我错误来自于创建关联数组$Tableau_comptes_dependants这里是代码
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,
)
);请让我知道我做错了什么
发布于 2017-09-07 16:10:14
通知是通过调用in_array生成的
if (!in_array($Mes_comptes_reels_dependant,
$Tableau_comptes_dependants[$Tableau_id_compte_fictif]))您尝试在一个不存在的索引25715上访问数组,因为这是您在方括号中传递的变量的值。
在访问索引之前,您应该首先检查isset是否存在索引。
也就是说,如果你遇到这样的问题,我认为你的代码有一个设计缺陷。你应该尝试重构它,或者和你的同事讨论如何简化它。我必须承认,虽然我可以,但我不会尝试为您解决这个问题,因为您的变量名基本上是不可读的。
https://stackoverflow.com/questions/46090841
复制相似问题