dougaxing8673 2011-03-08 06:04
浏览 44
已采纳

数组在php中返回错误未定义的索引

The index 4 exisits in array rating but i get error...if i undo the comments $write=4 then it works fine.

foreach($writers[$i] as $write)
      {
      echo "writer: $write  -  rating: ";
      print_r($rating);
//$write=4;
      echo "<br>". $rating[$write] ;

}

the above code gives

    writer: 4 
Notice: Undefined index: 4 in D:\wamp\www\shazia\CRM\EffortTrackUpload\admin\cron.php on line 232

The array rating gives:

Array ( [3] => 5.1 [4] => 6 [5] => 5.2 [6] => 5 [8] => 5 [9] => 5 [10] => 5 [11] => 4 [12] => 3.6 [13] => 5 [14] => 5.1 )

can anyone please help me explain what i am doing wrong.

Thanks

  • 写回答

4条回答 默认 最新

  • dongxi3209 2011-03-08 06:17
    关注

    As per your comment, the issue is that $write is a string - " 4", but the array index is just an integer 4.

    Work out why the 4 is padded with space in the $writers[$i] array, if you are getting the array from elsewhere you could use intval($write) to get the correct value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题