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 Basic PHP Website Listing and Sorting Inventory Items Displaying Item Details

Shorthand Syntax Solution

Thanks Alena Holligan for an amazing project series. It was enjoyable and I learned quite a bit. I wanted to share another approach using shorthand syntax which I feel can be helpful.

PHP Short Opening Tag

PHP Shorthand Control Structures

        <div class="media-details">
            <h1><?= $item["title"] ?></h1>
            <table>
                <tr>
                    <th>Category</th>
                    <td><?= $item["category"] ?></td>
                </tr>
                <tr>
                    <th>Genre</th>
                    <td><?= $item["genre"] ?></td>
                </tr>
                <tr>
                    <th>Format</th>
                    <td><?= $item["format"] ?></td>
                </tr>
                <tr>
                    <th>Year</th>
                    <td><?php $item["year"] ?></td>
                </tr>
                <?php if (strtolower($item["category"]) == "books") : ?>
                          <tr>
                            <th>Authors</th>
                            <td>
                              <?php foreach ($item['authors'] as $author) : ?>
                                  <?= $author . "<BR>" ?>
                              <?php endforeach; ?>
                            </td>
                          </tr>
                          <tr>
                            <th>Publisher</th>
                            <td><?= $item['publisher'] ?></td>
                          </tr>
                          <tr>
                            <th>ISBN</th>
                            <td><?= $item['isbn'] ?></td>
                          </tr>
                <?php elseif (strtolower($item["category"]) == "movies") : ?>
                          <tr>
                            <th>Director</th>
                            <td><?= $item['director'] ?></td>
                          </tr>
                          <tr>
                            <th>Writers</th>
                            <td><?= implode(", ", $item['writers']) ?></td>
                          </tr>
                          <tr>
                            <th>Stars</th>
                            <td><?= implode(", ", $item['stars']) ?></td>
                          </tr>
                <?php elseif (strtolower($item["category"]) == "movies") : ?>
                          <tr>
                            <th>Artist</th>
                            <td><?= $item['artist'] ?></td>
                          </tr>
                <?php endif; ?>    
            </table>
        </div>