Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    array didn't work

    Hi,
    Not sure why the array page is not working when I called it on the browser. Can someone give a tip to see what was it wrong in the syntax? Much appreciated!
    PHP Code:
    <?php
            
    //assign the multiple array
            
    $price[0][0]=12;
            
    $price[0][1]=25;
            
    $price[1][0]=36;
            
    $price[1][1]=48;
            
    $price[2[0]=11;
            
    $price[2][1]=77;
            
            
    //assign the multiple array
            
    $data=array("name"=>array("Linda""Alice","Elvin"),
                        
    "value"=>array("123","456","789"),
                        
    "address"=>array("Frankfurt","Zurich","Madrid"));
            
            
            
    //assign the multiple array
            
    for($a=0$a<3$a++){
                echo 
    "<p>";
                    for(
    $b=0$b<2;$a++){
                        echo 
    "\$price[$a][$b] = ".$price[$a][$b]. "<br>";
                    }
                echo 
    "</p>";
            }
            
            
    //displaying table with multiple array
            
    echo "<table bgcolor='#ffccff' border='2' width='70%'><tr>";
                for(
    $a=0$a<3$a++){
                    echo 
    "<td>".$data["name"][$a]."</td>";
                }
                
            echo 
    "</tr><tr>";
                for(
    $a=0$a<3;$a++){
                    echo 
    "<td>".$$data["value"][$a]."</td>";
                }
            echo 
    "</tr><tr>";
                for(
    $a=0$a<3$a++){
                    echo 
    "<td>".$data.["address"][$a]. "</td>";
                }
            echo 
    "</tr></table>";
            
    ?>

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what did it display

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Comments where things were fixed...:
    PHP Code:
            //assign the multiple array
            
    $price[0][0]=12;
            
    $price[0][1]=25;
            
    $price[1][0]=36;
            
    $price[1][1]=48;
            
    $price[2][0]=11// missing ]
            
    $price[2][1]=77;
            
            
    //assign the multiple array
            
    $data=array("name"=>array("Linda""Alice","Elvin"),
                        
    "value"=>array("123","456","789"),
                        
    "address"=>array("Frankfurt","Zurich","Madrid"));
            
            
            
    //assign the multiple array
            
    for($a=0$a<3$a++){
                echo 
    "<p>";
                    for(
    $b=0$b<2;$b++){ // was $a++
                        
    echo "\$price[$a][$b] = ".$price[$a][$b]. "<br>";
                    }
                echo 
    "</p>";
            }
            
            
    //displaying table with multiple array
            
    echo "<table bgcolor='#ffccff' border='2' width='70%'><tr>";
                for(
    $a=0$a<3$a++){
                    echo 
    "<td>".$data["name"][$a]."</td>";
                }
                
            echo 
    "</tr><tr>";
                for(
    $a=0$a<3;$a++){
                    echo 
    "<td>".$data["value"][$a]."</td>"// extra $
                
    }
            echo 
    "</tr><tr>";
                for(
    $a=0$a<3$a++){
                    echo 
    "<td>".$data["address"][$a]. "</td>"// missing [
                
    }
            echo 
    "</tr></table>"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •