PHP PHP Arrays and Control Structures PHP Conditionals Switch Statements

I don't understand the question

Hi, I'm confused what I need to do here.

switch.php
<?php
//Available roles: admin, editor, author, subscriber
if (!isset($role)) {
    $role = 'subscriber';
}

//change to switch statement
switch ($role) {
  case (!="admin") :
    echo "You do not have access to this page. Please contact your administrator.";
  case "admin" :
    echo "As an admin, you can add, edit, or delete any post.";
  default :
    echo "You do not have access to this page. Please contact your administrator.";
}

2 Answers

Daniel Baker
Daniel Baker
15,353 Points

Bummer: syntax error, unexpected '!=' (T_IS_NOT_EQUAL) in switch.php on line 9

//original
case (!="admin") :
//Fixed
case !"admin":

There are more errors in the code but this will get you to the next error.

Remember to break; the switch.

Daniel Baker
Daniel Baker
15,353 Points

Also, it looks like it is looking specifically for

case "admin":

vs

case "admin" :

Thanks Daniel, spotted the : issue just now, and got the code working, it was simpler than I thought.

I fixed it thanks Daniel.

<?php //Available roles: admin, editor, author, subscriber if (!isset($role)) { $role = 'subscriber'; }

//change to switch statement switch ($role) { case "admin": echo "As an admin, you can add, edit, or delete any post."; break; default: echo "You do not have access to this page. Please contact your administrator."; }