Are there alternative methods to using eval() in PHP for evaluating user-generated conditions securely?

Using eval() in PHP to evaluate user-generated conditions can be a security risk as it allows arbitrary code execution. An alternative method to securely evaluate user-generated conditions is to use a switch statement with predefined cases that the user input can match against. This way, only specific conditions can be evaluated, reducing the risk of code injection.

$user_condition = "condition_1";

switch($user_condition) {
    case "condition_1":
        // logic for condition 1
        break;
    case "condition_2":
        // logic for condition 2
        break;
    default:
        // default logic
}