I did this code:
index.php:
$series = array(
"a" => array(
"b" => array(
"FOLD", "more_arrays.php"
),
"b2" => array(
)
)
);
function pre($a) { print "<pre>"; print_r($a); print "</pre>"; }
$string = "a,,,b";
$all_directions = explode(",,,", $string);
$all_directions = array_map("trim", $all_directions);
$b = ""; $g = 0;
foreach($all_directions as $v)
{
$b .= "['".str_replace(array("[", "]", "'", "\""), null, $v)."']";
$g++;
}
@eval('$where = $series'.$b.';');
if(isset($where[0]) && $where[0] == "FOLD")
{
// a[series], b[series], c[new_array]
require_once("./more_folders/".$where[1]);
print $g;
}
for($i = 0; $i <= sizeof($where); $i++)
{
}
pre($where);
more_array.php:
$series_in = array(
"c" => array(
"d" => array(
"bla" => array(),
"hey" => array(),
"ha" => array()
),
"d2" => array(
)
),
"c2" => array(
)
)
At $string I define which "folder" I want to see, for example if I write $string = "a";
it will show all the arrays inside "a".
key = the name of the folder, value = the subfolders inside the folder and those array.
Now: Because it's going to be a huge array, I want to separate it to many arrays. If you see at the code, $series[a][b]
direct lead to another array.
Now if I do $string = "a,,,b";
I want to see: "c" and "c2"
and if I do $string = "a,,,b,,,c";
I want to see: "d", "d2"
and if I do $string = "a,,,b,,,c,,,d";
I want to see all inside d ( "bla", "hey", "ha" ..)
How can I do this?
I'll bite...
You seem to have most of the parts. Basically you need to put them together in a loop.
You've $string
and $series
. Then you split $string
into your $all_directions
. Loop thru $all_directions
, each time diving down into the array $series = $series[$all_directions[$i]];
When you've done the last $all_directions
return $series
(but watch for running out of $series
, return null, or false if you're sure that would be an error).
The only other thing is any time $series[$all_directions[$i]]
is the special "FOLD" entry then first load the file and assign it on-the-fly something like include ...; $series[$all_directions[$i]] = $series_in;
You don't want and don't need eval()
and the loop is better using for
because you need to check "FOLD"
in the key (I'd also say use a recursive function but you said the array can be very big so it might hurt performance).