PHP 定义以子数组为索引的数组

PHP define array with sub arrays as an index

我正在使用 PHP 文件来定义一些要在另一个应用程序中使用的数据。

我认为这是声明我的数组的有效方式.. 使用子数组作为索引。

但显然不是..

//question 1
$quiz['question'][0] = "xxx";
$quiz['question'][0]['answer'][0] = "xxx";
$quiz['question'][0]['answer'][1] = "xxx";
$quiz['question'][0]['answer'][2] = "xxx";
$quiz['question'][0]['answer'][3] = "xxx";
$quiz['question'][0]['answer'][4] = "xxx";  

如何正确定义这些 easily/legible 数组?

我目前正在收到这个 error/warning:

警告:非法字符串偏移'answer'

你在第一行明确地说 $quiz['question'][0] 是一个字符串,然后你试图表现得好像它是一个数组,这就是你得到这个错误的原因

如何定义,一种方式

$quiz['question'][0]['question'] = "How to define an array";
$quiz['question'][0]['answer'][0] = "Like this";
$quiz['question'][0]['answer'][1] = "or like that";
$quiz['question'][0]['answer'][2] = "or maybe like the other";
print_r($quiz);

结果

Array
(
    [question] => Array
        (
            [0] => Array
                (
                    [question] => How to define an array
                    [answer] => Array
                        (
                            [0] => Is it like this
                            [1] => Or isit like that
                            [2] => Or is it like the other
                        )

                )

        )

)