How to map a file to multidimensional array?
Posted: Wed Jun 02, 2004 2:10 pm
Hi .
Assume i have this code in a file called array.txt
and i want to map it on a real array like $array. I mean the $array will be:
How can this be done???
I tried eval() but it does not work as expected.
Assume i have this code in a file called array.txt
Code: Select all
<?php
array(
1 => array(
'title' => 'Menu item 1',
'url' => '/item1.php',
'sub' => array(
11 => array('title' => 'Menu item 1.1', 'url' => '/item1.1.php'),
12 => array(
'title' => 'Menu item 1.2',
'url' => '/item1.2.php',
'sub' => array(
121 => array('title' => 'Menu item 1.2.1', 'url' => '/item1.2.1.php'),
122 => array('title' => 'Menu item 1.2.2', 'url' => '/item1.2.2.php')
)
)
)
),
2 => array(
'title' => 'Menu item 2',
'url' => '/item2.php',
'sub' => array(
21 => array('title' => 'Menu item 2.1', 'url' => '/item2.1.php'),
22 => array('title' => 'Menu item 2.2', 'url' => '/item2.2.php')
)
)
);
?>Code: Select all
$array=array(1 => array(
'title' => 'Menu item 1',
'url' => '/item1.php',
'sub' => array(
11 => array('title' => 'Menu item 1.1', 'url' => '/item1.1.php'),
12 => array(
'title' => 'Menu item 1.2',
'url' => '/item1.2.php',
'sub' => array(
121 => array('title' => 'Menu item 1.2.1', 'url' => '/item1.2.1.php'),
122 => array('title' => 'Menu item 1.2.2', 'url' => '/item1.2.2.php')
)
)
)
),
2 => array(
'title' => 'Menu item 2',
'url' => '/item2.php',
'sub' => array(
21 => array('title' => 'Menu item 2.1', 'url' => '/item2.1.php'),
22 => array('title' => 'Menu item 2.2', 'url' => '/item2.2.php')
)
)
);I tried eval() but it does not work as expected.