Given the names of some user-defined functions stored as strings in variables. The task is to call the functions using the names stored in the variables.
There are two methods for doing this. One is directly calling function by variable name using bracket and parameters and the other is by using call_user_func() Function but in both method variable name is to be used.
hello geek hello fun_function
Another Method: Using eval() Function: The eval() function is an inbuilt function in PHP which is used to evaluate string as PHP code.
Note: This method is contributed by Vineet Joshi.
eval( $code )
Parameters: This function accepts single parameter code which is used to hold the PHP code as a string.
Welcome to GeeksforGeeks!
- How to call PHP function on the click of a Button ?
- Search in a sorted 2D matrix (Stored in row major order)
- Print PHP Call Stack
- How to get a variable name as a string in PHP?
- PHP | Check if a variable is a function
- How to remove error Call to undefined function curl_init()?
- How to call a function automatically after waiting for some time using jQuery?
- How to call functions after previous function is completed in jQuery ?
- How to declare a global variable in PHP?
- How to get cookies from curl into a variable in PHP ?
- PHP | Unset Session Variable
- Variable-length argument list in PHP
- How to check whether a variable is set or not using PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.