Nope. The “index” array is not really useful, because the “vals” array already has those same index values… I’m just not displaying them above as keys of the outer foreach loop. Above, you were looking at the inner foreach loop only.
Here, see the index values now…
array (
0 =>
array (
‘tag’ => ‘AIML’,
‘type’ => ‘open’,
‘level’ => 1,
),
1 =>
array (
‘tag’ => ‘CATEGORY’,
‘type’ => ‘open’,
‘level’ => 2,
),
2 =>
array (
‘tag’ => ‘PATTERN’,
‘type’ => ‘complete’,
‘level’ => 3,
‘value’ => ‘ONE’,
),
3 =>
array (
‘tag’ => ‘TEMPLATE’,
‘type’ => ‘open’,
‘level’ => 3,
‘value’ => ’ I like ‘,
),
4 =>
array (
‘tag’ => ‘RANDOM’,
‘type’ => ‘open’,
‘level’ => 4,
),
5 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘red’,
),
6 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘green’,
),
7 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘blue’,
),
8 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘white’,
),
9 =>
array (
‘tag’ => ‘RANDOM’,
‘type’ => ‘close’,
‘level’ => 4,
),
10 =>
array (
‘tag’ => ‘RANDOM’,
‘type’ => ‘open’,
‘level’ => 4,
),
11 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘shoes’,
),
12 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘pants’,
),
13 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘turtles’,
),
14 =>
array (
‘tag’ => ‘RANDOM’,
‘type’ => ‘close’,
‘level’ => 4,
),
15 =>
array (
‘tag’ => ‘TEMPLATE’,
‘value’ => ‘, but not when they have ‘,
‘type’ => ‘cdata’,
‘level’ => 3,
),
16 =>
array (
‘tag’ => ‘RANDOM’,
‘type’ => ‘open’,
‘level’ => 4,
),
17 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘stripes’,
),
18 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘polka-dots’,
),
19 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘buttons’,
),
20 =>
array (
‘tag’ => ‘LI’,
‘type’ => ‘complete’,
‘level’ => 5,
‘value’ => ‘some sort of disease’,
),
21 =>
array (
‘tag’ => ‘RANDOM’,
‘type’ => ‘close’,
‘level’ => 4,
),
22 =>
array (
‘tag’ => ‘TEMPLATE’,
‘value’ => ‘.’,
‘type’ => ‘cdata’,
‘level’ => 3,
),
23 =>
array (
‘tag’ => ‘TEMPLATE’,
‘type’ => ‘close’,
‘level’ => 3,
),
24 =>
array (
‘tag’ => ‘CATEGORY’,
‘type’ => ‘close’,
‘level’ => 2,
),
25 =>
array (
‘tag’ => ‘AIML’,
‘type’ => ‘close’,
‘level’ => 1,
),
)
And I am calling the xml_parse_into_struct function without the 4th argument for index. The 4th argument is optional.