duanniubeng2265 2017-04-11 10:53
浏览 70
已采纳

数组中数组的非法字符串偏移量

I have the main array called $quizzes which contains the collection of $Quiz. Each $Quiz has the following fields: $Quiz['correct'] gives me the number of correct questions.

I can get the number of correct questions for 12th quiz using $quizzes[12]['correct']

However, since these quizzes are not displayed in order, I decided to define a new array:

$listoftests = array('$quizzes[30]','$quizzes[51]');

In my head, $listoftests[0]['correct'] should be equal to $quizzes[30]['correct'] but it's giving me

Warning: Illegal string offset 'correct' in /demo.php on line 14 $

when I try to echo $listoftests[0]['correct'];

  • 写回答

4条回答 默认 最新

  • douhui1630 2017-04-11 10:56
    关注

    In this $listoftests = array('$quizzes[30]','$quizzes[51]'); These are considered as two strings $quizzes[30] and $quizzes[51]. You should remove single quotes ' and try again.

    Change this:

    $listoftests = array('$quizzes[30]','$quizzes[51]');
    

    To:

    $listoftests = array($quizzes[30],$quizzes[51]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况