The example in this article describes how to create a function from a string in php. 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 shown in the example:
Copy code The code is as follows:
$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);
?>
I hope this article will be helpful to everyone’s PHP programming design.