- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to call a function from a string stored in a variable PHP?
To call a function from a string stored in a variable, use $func.
The syntax is as follows
$func=’anyFunctionName’;
Example
The PHP code is as follows
<!DOCTYPE html> <html> <body> <?php function hello(){ echo "Calling hello method."."<br>"; } function welcome(){ echo "Calling welcome method."."<br>"; } $func = 'hello'; $func(); ?> </body> </html>
Output
This will produce the following output
Calling hello method.
- Related Articles
- How to call a function of a module from a string with the function's name in Python?
- How to call a function of a module from a string with the function's name in Python?
- How to turn a String into a JavaScript function call?
- How to get a variable name as a string in PHP?
- How to call a JavaScript function from C++?
- How to Call a Lua function from C?
- How to call a JavaScript Function from Chrome Console?
- How to call a function inside a jQuery plugin from outside?
- How to call a parent class function from derived class function in C++?
- How to call a JavaScript function from an onClick event?
- How to call a JavaScript function from an onsubmit event?
- How to call a JavaScript function from an onmouseover event?
- How to call a JavaScript function from an onmouseout event?
- How to call a function in JavaScript?
- How to call a stored procedure using select statement in MySQL?

Advertisements