...

View Full Version : array didn't work



begeiste
08-30-2007, 12:12 AM
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
//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>";

?>

flann
08-30-2007, 12:14 AM
what did it display

Inigoesdr
08-30-2007, 12:22 AM
Comments where things were fixed...:

//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>";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum