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 trialCliff Jackson
2,887 PointsSyntax error when adding switch statement??
When i add the switch statement i get this error??
Brendon Butler
4,254 PointsCan you post your code?
3 Answers
Richard Hall
9,139 PointsYou 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
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
2,887 PointsThanks it was an error in the video again not the first time. She did not add the curly brace after the break.
Julian Helmholz
3,242 Pointsnobody, including you is perfect ;)
Cliff Jackson
2,887 PointsCliff Jackson
2,887 PointsParse 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