我收到此错误:
注意:数组php中的未定义偏移量
有谁知道我的错误在哪里?
//$forme count of my array
for( $counter = 0; $counter < $forme; $counter++ ) {
if($az[$counter] > 0)
{
$test=$connect->fetch_all("select * from `tbl_jobs_numbers` where `sub_id`='".$Subid[$counter]."' && `job_id`='".$JobID."' && `city_id`='".$ostan."' limit '".$az [ $counter ]."' , '".$ta[ $counter ]."'") ;
foreach($test as $puriya)
{
print $mobiles=$puriya['number']."<br/>";
}
}
else
{
$test=$connect->fetch_all("select * from `tbl_jobs_numbers` where `sub_id`='".$Subid[$counter]."' && `job_id`='".$JobID."' && `city_id`='".$ostan."' ") ;
foreach($test as $puriya)
{
//print $mobiles=$puriya['number']."<br/>";
}
}
}
答案 0 :(得分:0)
如果要迭代数组的每个项目,更简单的方法是使用foreach
(基于不是:
// array_values to make sure that the keys are numeric
foreach (array_values($az) as $index => $item) {
if ($item > 0) {
$test=$connect->fetch_all("select * from `tbl_jobs_numbers` where `sub_id`='".$Subid[$index]."' && `job_id`='".$JobID."' && `city_id`='".$ostan."' limit '".$az[$index]."' , '".$ta[$index]."'") ;
foreach($test as $puriya)
{
print $mobiles=$puriya['number']."<br/>";
}
} else {
$test=$connect->fetch_all("select * from `tbl_jobs_numbers` where `sub_id`='".$Subid[$index]."' && `job_id`='".$JobID."' && `city_id`='".$ostan."' ") ;
foreach($test as $puriya)
{
//print $mobiles=$puriya['number']."<br/>";
}
}
}
这应避免$az
的未定义索引错误。