Array of array...please help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    #1

    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($arra y, $level){
    while(list($k,$ v) = each($array)){
    if(is_array($ar ray[$k])){ //go into the array and print elements
    print("$k -><br>");
    $level++;
    printtree($arra y[$k],$level);
    }
    else
    print("$k : $v<br>");
    }
    }

    this works just fine !!!!

    Get crazy....

    BoB



  • Bob Bedford

    #2
    Re: Array of array...please help

    Sorry, found...
    here is the solution (for interested people...)

    echo("Name:".$r es["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" <bedford1@YouKn owWhatToDoHereh otmail.com> a écrit dans le
    message de news:40e180d6$0 $26637$5402220f @news.sunrise.c h...[color=blue]
    > 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"[/color]
    doesn't[color=blue]
    > work.
    >
    > I've already created a function by passing such reference:
    > function printtree($arra y, $level){
    > while(list($k,$ v) = each($array)){
    > if(is_array($ar ray[$k])){ //go into the array and print elements
    > print("$k -><br>");
    > $level++;
    > printtree($arra y[$k],$level);
    > }
    > else
    > print("$k : $v<br>");
    > }
    > }
    >
    > this works just fine !!!!
    >
    > Get crazy....
    >
    > BoB
    >
    >
    >
    >[/color]



    Comment

    Working...