PHP PHP Arrays and Control Structures PHP Conditionals Switch Statements

kingdavid igbayilola
kingdavid igbayilola
8,678 Points

php

i am trying to convert the if statement to a switch statement

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

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