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!

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 Todo App

I don't understand the purpose of $status variable.

$status = 'all';

$order = array(); $field = 'priority';

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

/////////////////// $status variable is string and $item['complete'] is boolean. How the compare here will work!! They are not same type!! if ($item['complete'] ===$status) { $order[] = $key; }

2 Answers

Corey Montgomery
Corey Montgomery
18,468 Points

Apparently from what I can tell and looking at other peoples questions on this topic, it is an error in the video. In this post: https://teamtreehouse.com/community/please-status-true-issue it appears the solution was found by a couple other people already.

Waqar Mohammad provides the solution which is to change the condition of the first if to ($status === "all") instead of ($status == "all").

The reason for this is further explained by Alexandre Babeanu who explains the difference between == and === in php when comparing boolean and strings. He states "When status is set to true then status it is set as a boolean. when comparing a boolean to a string with == php will look either for an empty string (false) or for not an empty string (true)."

Their answers should provide you with the information you seek and deserve all credit.

Any help