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

Robert Geranis
Robert Geranis
2,380 Points

Switch statement not working

I am working on this code for the switch statement:

<?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; }

Everything was working before, and now I am getting the following error:

Notice: Use of undefined constant ‘sort’ - assumed '‘sort’' in /home/treehouse/workspace/todo.php on line 6

The table no longer sorts by priority.

I have gone through this line-by-line, but I must have missed something. Can anyone offer some guidance?

2 Answers

Amy Kelly
Amy Kelly
3,588 Points

For some reason the apostrophe for $action is ‘sort’ which is why it is assuming '‘sort’'. This has maybe happened due to copying and pasting something. The correct apostrophe should be 'sort' not ‘sort’.

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

not

$status = 'all'; $field = 'priority'; $action = ‘sort’;
Robert Geranis
Robert Geranis
2,380 Points

Amy:

Thanks so much. I have been taking notes and entering code in the workspace, I must have copied code out of word that time. That fixed it.

Bob