PHP: Other Conditionals

Derek Bridge

Department of Computer Science,
University College Cork

PHP: Other Conditionals

Aims:

Class exercise

Class exercise

The conditional operator

The conditional operator

The conditional operator

The switch statement

The switch statement

if ( $x == 0 )
{
    do something
}
elseif ( $x == 1 )
{
    do something
}
elseif ( $x == 2 )
{
    do something
}
else
{
    do something
}
switch ( $x )
{
    case 0:
    {
        do something;
        break;
    }
    case 1:
    {
        do something;
        break;
    }
    case 2:
    {
        do something;
        break;
    }
    default:
    {
        do something;
        break;
    }
}