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

ternary operator

My code is,

$num_1 = 9; $num_2 = 9;

define("NUM_3",23); define('NUM_4',78);

$numbers = array(345,23,97,25,4);

echo $num_1 <= $num_2 and NUM_3 >= NUM_4 ? "Yes": "No";

It suppose to print "Yes" or "No" to the page. Instead it prints 1 to the page. Can anyone explain this to me please.

1 Answer

Chuck Emory
Chuck Emory
14,476 Points

First, if you trying to trying determine if $num_1 = NUM_4, you need to use == (equal comparison operator) instead of =. Right now you're saying you want $num_1 to be the same as NUM_4. At said, when I test your code using the == it echoes back 'No' like it should. If you are getting anything else, you may have something else in your code causing the issue. Try pulling out just the code you're having issue with and using a PHP tester (like http://phptester.net/) to help evaluate your code.