468,242 Members | 1,626 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,242 developers. It's quick & easy.

Array of array...please help

Still having problem with array of arrays. Here is the code:

echo("Name:
".$res["XMLTREE"]["DATAS"][0]["MODELE"]["0"]["MODELNAME"]."<br>");
//$res["XMLTREE"]["DATAS"][0]["MODELE"] is an array with many MODELNAME
while(list($k,$v) = each($res["XMLTREE"]["DATAS"][0]["MODELE"])){
echo("Name: ".$res[$k]["0"]["MODELNAME"]."<br>");

While the first line (the echo) works fine, the echo in the "while" doesn't
work.

I've already created a function by passing such reference:
function printtree($array, $level){
while(list($k,$v) = each($array)){
if(is_array($array[$k])){ //go into the array and print elements
print("$k -><br>");
$level++;
printtree($array[$k],$level);
}
else
print("$k : $v<br>");
}
}

this works just fine !!!!

Get crazy....

BoB

Jul 17 '05 #1
1 1319
Sorry, found...
here is the solution (for interested people...)

echo("Name:".$res["XMLTREE"]["DATAS"][0]["MODELE"]["0"]["MODELNAME"]."<br>")
;
while(list($k,$v) = each($res["XMLTREE"]["DATAS"][0]["MODELE"])){
//wrong: echo("Name: ".$res[$k]["0"]["MODELNAME"]."<br>");
echo("Name: ".$res[$k]["MODELNAME"]."<br>");
//the ["0"] is included in the $k element

BoB

"Bob Bedford" <be******@YouKnowWhatToDoHerehotmail.com> a écrit dans le
message de news:40***********************@news.sunrise.ch...
Still having problem with array of arrays. Here is the code:

echo("Name:
".$res["XMLTREE"]["DATAS"][0]["MODELE"]["0"]["MODELNAME"]."<br>");
//$res["XMLTREE"]["DATAS"][0]["MODELE"] is an array with many MODELNAME
while(list($k,$v) = each($res["XMLTREE"]["DATAS"][0]["MODELE"])){
echo("Name: ".$res[$k]["0"]["MODELNAME"]."<br>");

While the first line (the echo) works fine, the echo in the "while" doesn't work.

I've already created a function by passing such reference:
function printtree($array, $level){
while(list($k,$v) = each($array)){
if(is_array($array[$k])){ //go into the array and print elements
print("$k -><br>");
$level++;
printtree($array[$k],$level);
}
else
print("$k : $v<br>");
}
}

this works just fine !!!!

Get crazy....

BoB


Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Roy J | last post: by
1 post views Thread by Stephen | last post: by
33 posts views Thread by Peace | last post: by
44 posts views Thread by svata | last post: by
11 posts views Thread by Sudzzz | last post: by
6 posts views Thread by =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.