• Как с помощью SWITCH выбрать ФУНКЦИЮ?

    orlov0562
    @orlov0562 Куратор тега PHP
    I'm cool!
    $func = 'trim';
    if (function_exists($func)) echo call_user_func($func,' Test ');


    или твой пример

    $_POST['function'] = 'trim';
    $array = [' a', 'b '];
    $allowedFunctions = ['trim'];
    
    if (function_exists($_POST['function']) && in_array($_POST['function'], $allowedFunctions)) {
        $results = array_map($_POST['function'], $array);
        print_r($results);
    }
    Ответ написан
    Комментировать