Solution 1:
You can use call_user_func() to call a function dynamically:
👉 PHP Manual – call_user_func()
// Call a function by its name
echo call_user_func('time'); // works with native functions
// Example with arguments
function greet($name) {
return "Hello, $name!";
}
echo call_user_func('greet', 'Ashish');
// Output: Hello, Ashish!
Key Points:
The first argument is a string with the function name.
The second argument (and beyond) are the parameters passed to that function.
Works with user-defined functions and built-in functions (e.g., time()).
✅ This is useful when the function name is stored in a variable or comes from a dynamic source.