-
help me musicman, you're my only hope
Well, maybe Ben Kenobi can help me as well, if he's any good with PHP?
I am trying to do something I have achieved in Flash but not in PHP.
Basically it is breaking a long, delimitered string into an array.
I broke the string into a three dimensional array in flash using the code below:
This nis the Flash::::::
__________________________________________________ ________________
tmpMenu = loadedMenu.split("^");
// EXAMPLE of what tmpMenu looks like after this:
//mainMenu="|1|,nav,a,|2|,nav,a1,|3|,txt,a11,|3|,txt ,a12,|2|,nav,a2,|3|,txt,a21";
for(a=3; a<tmpMenu.length; a++) {
// split lvl 1
tmpArr = tmpMenu[a].split(",");
if (tmpArr[1] != "nav") {
tmpMenu[a] = tmpMenu[a].split(",");
} else {
tmpMenu[a] = tmpMenu[a].split(",|2|");
tmpArr = tmpMenu[a][0].split(",");
tmpMenu[a].splice(0, 1, tmpArr[0], tmpArr[1], tmpArr[2]);
// split lvl 2
for (b=3; b<tmpMenu[a].length; b++) {
tmpArr = tmpMenu[a][b].split(",");
if (tmpArr[1] != "nav") {
tmpMenu[a][b] = tmpMenu[a][b].split(",");
if (tmpMenu[a][b][0] == "") {
tmpMenu[a][b][0] = "|2|";
}
} else {
tmpMenu[a][b] = tmpMenu[a][b].split(",|3|");
tmpArr = tmpMenu[a][b][0].split(",");
if (tmpArr[0] == "") {
tmpArr[0] = "|2|";
}
tmpMenu[a][b].splice(0, 1, tmpArr[0], tmpArr[1], tmpArr[2]);
// split lvl 3
for (c=3; c<tmpMenu[a][b].length; c++) {
tmpMenu[a][b][c] = tmpMenu[a][b][c].split(",");
if (tmpMenu[a][b][c][0] == "") {
tmpMenu[a][b][c][0] = "|3|";
}
}
}
}
}
}_________________________________________________ _________________
I was wondering how I could do it in PHP?
It's ultimately to create a dropdown menu in PHP with three levels.
Any clues would be fantastic as I don't know where to start?
-
Hi,
here is code that converts a structure like yours into a multi-level array:
Code:
<?
$navtree = array();
$navptr[0] = &$navtree;
$currlev = 0;
$temp = array();
$input = split(",", "|1|,nav,a,|2|,nav,a1,|3|,txt,a11,|3|,txt,a12,|2|,nav,a2,|3|,txt,a21")
for($n = 0 ; $n < count($input) ; $n +=3)
{ $type = $input[$n+1];
$label = $input[$n+2];
if(!ereg('\|([0-9])\|', $input[$n], $matched))
die("problem near $n");
$level = $matched[1];
if($level > $currlev+1)
die("preobelm ner $n");
if($type == "txt")
$navptr[$level-1][] = array(type => $type, label => $label);
else
{ //$temp["curr$n"] = array();
$nm = "curr$n";
$$nm = array();
$navptr[$level-1][] = array(type => $type, label => $label, sub => &$$nm);
$navptr[$level] = &$$nm;
$currlev = $level;
}
}
var_dump($navtree);
?>
Musicman
-
Thanks heaps for that, I really appreciate you taking the time.
I'll look into it and see what I can come up with.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|