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

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路