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 Conditionals Operators

Cristian Gerardo Hernandez Barrios
Cristian Gerardo Hernandez Barrios
28,382 Points

I can't understand :s

I don't know how to resolve that problem, i think is very difficult, i watched the videos, but this excersise is weird.

Please help

Thanks

index.php
<?php
$username = 'sketchings';
//Available roles: author, editor, admin
$role = 'editor';

//add conditional statement
if($username == 'sketchings'){

}
echo "You do not have access to this page. Please contact your administratior.";

1 Answer

Clare A
Clare A
23,994 Points

Hi Cristian,

The challenge asking us to create a single 'if' statement that uses a logical operator (like in the previous video) to check 2 conditions;

  1. Is the $username variable set? AND(&&)
  2. Is the $role NOT equal to (!=) 'admin'

If the condition is true, then echo "You do not have access to this page. Please contact your administrator."

<?php
if ( isset($username) && $role != "admin" ) {
  echo "You do not have access to this page. Please contact your administratior.";
} else {
  echo "The statement evaluates to false";
}

Hope this helps.