Validate a value against a small set of allowed strings.

Enum Choices

enum_choice.php
<?php
$role = ;
$allowed = in_array($role, ["admin", "editor", "guest"], true);
$status = $allowed ? "accepted" : "rejected";

echo "role=" . $role . "\n";
echo "status=" . $status . "\n";
<?php
$role = ;
$allowed = in_array($role, ["admin", "editor", "guest"], true);
$status = $allowed ? "accepted" : "rejected";

echo "role=" . $role . "\n";
echo "status=" . $status . "\n";
<?php
$role = ;
$allowed = in_array($role, ["admin", "editor", "guest"], true);
$status = $allowed ? "accepted" : "rejected";

echo "role=" . $role . "\n";
echo "status=" . $status . "\n";
enum-choice Many inputs must be one of a few known values. `in_array` can compare against an immediate list and produce a scalar decision.