Page 1 of 1

Array problem

Posted: Mon Jul 21, 2003 2:29 am
by heavensangel
im creating a simple php program using array but i have a problem in printing array when using double quotes("") ,im experimenting on using for each, while loops and using the manual way of accessing arrays, when i use the manual way and try to put a double quotes, the browser interprets them literally. but if i removed the double quotes i result is correct, please explain the way PHP interprets array, and why is it that i need to use concatenation operator in printing array element... can you please explain the reasons... thanks

heres the code:

$products = array(array("TIR","Tires",100),
array("OIL","Oil",50),
array("SPK","Spark plugs",10));

echo "MANUAL WAY OF ACCESSING ARRAY<BR>";
echo "$products[0][0].$products[0][1].$products[0][2]<br>"; // THIS LINE OF CODE WILL BE INTERPRETED LITERALLY BECAUSE I PUT A DOUBLE QUOTE! WHY?

echo $products[1][0].$products[1][1].$products[1][2]."<BR>"; // THIS ONE WILL GIVE ME THE CORRECT ANSWER.
echo $products[2][0].$products[2][1].$products[2][2]."<BR>";

Code: Select all

<?php

?>

Code: Select all

<?php

?>

Posted: Mon Jul 21, 2003 12:01 pm
by m@ndio
if you try and put an array into double quotes I don't think it likes it too much as php tries to interpret this as a string... I have always used the following method:

Code: Select all

//array above

echo $products[0][0]."<br>".$products[0][1]."<br>".$products[0][2]."<br>";