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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀