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 PHP Arrays and Control Structures PHP Loops Sorting Multidimensional Arrays

Cliff Jackson
Cliff Jackson
2,887 Points

Syntax error when adding switch statement??

When i add the switch statement i get this error??

Cliff Jackson
Cliff Jackson
2,887 Points

Parse error: syntax error, unexpected end of file, expecting case (T_CASE) or default (T_DEFAULT) or '}' in /home/treehouse/workspace/todo.php on line 60

3 Answers

Richard Hall
Richard Hall
9,139 Points

You are missing the final curly brace on your switch statement. Try to focus on your code formatting, it will help make these errors more noticeable.

<?php 
include 'list.php';

$status = 'all';
$field = 'priority';
$action = 'sort';

$order = array();
if ($status == 'all') {
    $order = array_keys($list);
} else {
    foreach ($list as $key => $item) {
        if ($item['complete'] == $status) {
            $order[] = $key;
        }
    }
}

switch ($action) {
    case 'sort':
        if ($field) {
            $sort = array();
            foreach ($order as $id) {
                $sort[$id] = $list[$id][$field];
            }
            asort($sort);
            $order = array_keys($sort);
        }
        break;
} // <--- Your missing curly brace. 
Cliff Jackson
Cliff Jackson
2,887 Points

<?php include 'list.php';

$status = 'all'; $field = 'priority'; $action = 'sort';

$order = array(); if ($status == 'all') { $order = array_keys($list); } else { foreach ($list as $key => $item) { if ($item['complete'] == $status) { $order[] = $key; } } }

switch ($action) { case 'sort': if ($field) { $sort = array(); foreach ($order as $id) { $sort[$id] = $list[$id][$field]; } asort($sort); $order = array_keys($sort); } break;

Cliff Jackson
Cliff Jackson
2,887 Points

Thanks it was an error in the video again not the first time. She did not add the curly brace after the break.

Julian Helmholz
Julian Helmholz
3,242 Points

nobody, including you is perfect ;)