Quiz: Introducing New PHP 8 OOP Features

Test your understanding of new OOP features in PHP 8.

1

Which option is the correct implementation of the following code in the match expression?

<?PHP
$color = 'blue';
switch ($color) {
    case 'red':
        echo 'This is a red color.';
        break;
    case 'green':
        echo 'This is a green color.';
        break;
    case 'blue':
        echo 'This is a blue color.';
        break;
    default:
        echo 'Unknown color.';
        break;
}
?>
A)
<?php
$color = 'blue';
$message = match ($color) {
    $message == 'red' => 'This is a red color.',
    $message == 'green' => 'This is a green color.',
    $message == 'blue' => 'This is a blue color.',
    default => 'Unknown color.'
};
}
B)
<?php
$color = 'blue';
$message = match ($color) {
    $color == 'red' => 'This is a red color.',
    $color == 'green' => 'This is a green color.',
    $color == 'blue' => 'This is a blue color.',
    default => 'Unknown color.'
};
}
C)
<?php
$color = 'blue';
$message = match ($color) {
    'red' => 'This is a red color.',
    'green' => 'This is a green color.',
    'blue' => 'This is a blue color.',
    default => 'Unknown color.'
};
}
D)
<?php
$color = 'blue';
$message = match($color) {
    'red' = 'This is a red color.',
    'green' = 'This is a green color.',
    'blue' = 'This is a blue color.',
    default = 'Unknown color.'
};
}
Question 1 of 50 attempted

Get hands-on with 1400+ tech skills courses.