How to call a function from a string stored in a variable with PHP?

Spread the love

Sometimes, we want to call a function from a string stored in a variable with PHP.

In this article, we’ll look at how to call a function from a string stored in a variable with PHP.

How to call a function from a string stored in a variable with PHP?

To call a function from a string stored in a variable with PHP, we can use a variable as the function name.

For instance, wewrite

$functionName()

to call the $functionName function.

$functionName is a string with the name of the function.

We can also use the call_user_func function to do the same thing by writing

call_user_func($functionName)

Conclusion

To call a function from a string stored in a variable with PHP, we can use a variable as the function name.

Leave a Reply

Your email address will not be published.