Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMarcus Burkhart
3,169 PointsPHP Syntax Error
Here is the error I get: Parse error: syntax error, unexpected '$products' (T_VARIABLE) on line 4
<?php
$products = array()
$products[101] = "Logo Shirt, Red";
$products[102] = "Mike the Frog shirt, Black";
$products[103] = "Mike the Frog shirt, Blue";
$products[104] = "Logo Shirt, Green";
?>
<?php
$pageTitle = "Mikes Full Catalog of Shirts";
$section = "shirts";
include('inc/header.php'); ?>
<div class="section page">
<div class="wrapper">
<h1>Mike’s Full Catalog of Shirts</h1>
<ul>
<?php foreach($products as $product) { ?>
<li><?php echo $product; ?></li>
<?php } ?>
</ul>
</div>
</div>
<?php include('inc/footer.php'); ?>
2 Answers
Yorick Toma
742 PointsYou should close the first line ^^
Dont forget your ;
<?php
$products = array();
Marcus Burkhart
3,169 PointsThanks... I thought it should possibly have been left open so we could add items to it. Guess I wasn't paying close enough attention.
Yorick Toma
742 PointsWe are at PHP 5 these days, so you can also use
<?php
$products = [];
Tong Vang
9,926 Points$products = array();
Marcus Burkhart
3,169 PointsMarcus Burkhart
3,169 PointsWhat am I doing wrong because this looks right ...?