Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Real Simple Question

Status
Not open for further replies.

wreikun

Technical User
Apr 23, 2002
63
US
Hello. I'm currently learning PHP from a book, and I'm on the "Arrays" section. However, I keep getting errors when I try to run the following PHP:

$products = array("Toys", "Electronics", "Books");
echo "$products";

All I want to do is put 'Toys', 'Electronics', and 'Books' into an array and then print it out. But I keep getting the following error:

Parse error: parse error, unexpected T_VARIABLE in /home/ray/public_html/phpfiles/array.php on line 75

Line 75 is referring to the top line.

Can anybody help?

--REI


 
You can't output array that easy...

Try this one:

for ($i = 0; $i < count ($array); $i++) {
echo $product[$i];
}

or (just for testing):

print_r($array);

HTH, Sascha cu, Sascha
 
thanks iTST. heres something that I cant figure out. whenever i attempt to run the following PHP:


$products = array(
array(
array(&quot;CAR_TIR&quot;, &quot;Car Tires&quot;, 100),
array(&quot;CAR_OIL&quot;, &quot;Car Oil&quot;, 10),
array(&quot;CAR_SPK&quot;, &quot;Car Spark Plugs&quot;, 4)
),
array(
array(&quot;VAN_TIR&quot;, &quot;Van Tires&quot;, 110),
array(&quot;VAN_OIL&quot;, &quot;Van Oil&quot;, 20),
array(&quot;VAN_SPK&quot;, &quot;Van Spark Plugs&quot;, 14)
),
array(
array(&quot;TRK_TIR&quot;, &quot;Truck Tires&quot;, 120),
array(&quot;TRK_OIL&quot;, &quot;Truck Oil&quot;, 30),
array(&quot;TRK_SPK&quot;, &quot;Truck Spark Plugs&quot;, 24)
)
);

for($layer=0; $layer<3; $layer++){ /* LINE 13 */
echo &quot;Layer $layer&quot;;
for($row=0; $row<3; $row++){
for($col=0; $col<3; $col++){
echo &quot; | &quot;.$products[$layer][$row][$col];
}
echo &quot;|&quot;;
}
}

I get the following error message:

Parse error: parse error, unexpected T_FOR in /home/ray/public_html/phpfiles/array2.php on line 13

I dont understand whats wrong. Some previous scripts I made using the 'for' statement was met with no problems. Im still huge newbie and any help is greatly appreciated.

--REI

 
i tested your code and everything is ok.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top