Home > Article > Backend Development > Explain how PHP creates functions from strings
How to create a function from a string in php? This article mainly introduces the method of creating functions from strings in PHP, using strings and create_function function in PHP to create functions. I hope to be helpful.
The example in this article describes how PHP creates functions from strings. Share it with everyone for your reference. The details are as follows:
In php, you can put the entire function definition into a string and define it dynamically. With the create_function function, you can dynamically create functions based on user input. It is very convenient. The use of create_function is as follows: Shown:
<?php $lambda =create_function('$a,$b','return(strlen($a)-strlen($b));'); $array = array('really long string here,boy', 'this', 'middling length','larger'); usort($array,$lambda); print_r($array); ?>
Related recommendations:
PHP Function Syntax Introduction 1_PHP Tutorial
php Function Usage and Function Definition Method_PHP Tutorial
The above is the detailed content of Explain how PHP creates functions from strings. For more information, please follow other related articles on the PHP Chinese website!