By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Array of array...please help

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.