我想构建一个深度嵌套的关联数组,但是我不知道构建它的规则。我有这个理论数组:
-one
-two
-three
-four
-one
-two
-three
-four
-five
-six
-seven
-eight
-nine
-one
-two
-three
-one
-two
-three
-four
-five
-six
我尝试将其表示为 PHP 关联数组:
$associative = array(
'one' => 'one-1',
'two' => 'two-2',
'three' => 'three-3',
'four' => 'four-4'
(
'one' => 'one-four-1',
'two' => 'two-four-2',
'three' => 'three-four-3',
'four' => 'four-four-4'
)
'five' => 'five-5',
'six' => 'six-6',
'seven' => 'seven-7',
'eight' => 'eight-8',
'nine' => 'nine-9'
(
'one' => 'one-nine-1',
'two' => 'two-nine-2',
'three' => 'three-nine-3'
(
'one' => 'one-nine-three-1',
'two' => 'two-nine-three-2',
'three' => 'three-nine-three-3',
'four' => 'four-nine-three-4',
'five' => 'five-nine-three-5',
'six' => 'six-nine-three-6'
))
);
$keys = array_values($associative);
echo $keys[0];
当我尝试执行php代码片段时,出现了以下错误:
解析错误:在C:\wamp\www\array.php的第7行,意外的 '(',期望 ')'。
所以我的问题是,编写此类数组的正确方式是什么?我希望添加更多子元素时应该遵循什么规则?
注:在我的虚拟数组中,数字4有四个子元素,数字9有三个子元素,数字3有六个子元素。无论如何,我希望你能理解在这个虚拟数组中“子元素”的含义。