This article describes how to create a function from a string in php, and describes how to use the string and create_function functions in php, for more information about how to create a function from a string in php, see the example in this article. Share it with you for your reference. The details are as follows:
In php, you can place the entire function definition in a string for dynamic definition. with the create_function function, you can dynamically create a function based on user input, which is very convenient, the usage of create_function is shown in the following example:
The code is as follows:
<? Php
$ Lambda = create_function ('$ a, $ B', 'Return (strlen ($ a)-strlen ($ B ));');
$ Array = array ('really long string here, boys', 'C', 'middling length', 'larger ');
Usort ($ array, $ lambda );
Print_r ($ array );
?>
I hope this article will help you with php programming.