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 trial

PHP Build a Simple PHP Application Listing Inventory Items Creating the Products Array

PHP 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&rsquo;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'); ?>

What am I doing wrong because this looks right ...?

2 Answers

You should close the first line ^^

Dont forget your ;

<?php
$products = array();

Thanks... I thought it should possibly have been left open so we could add items to it. Guess I wasn't paying close enough attention.

We are at PHP 5 these days, so you can also use

<?php

$products = [];
Tong Vang
Tong Vang
9,926 Points

$products = array();