Home > Backend Development > PHP Tutorial > How to create a function from a string in php, php string function_PHP tutorial

How to create a function from a string in php, php string function_PHP tutorial

WBOY
Release: 2016-07-13 10:03:35
Original
730 people have browsed it

How to create a function from a string in php, php string function

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968271.htmlTechArticleHow to create a function from a string in php, php string function This article explains how to create a function from a string in php method. Share it with everyone for your reference. The details are as follows: In php, you can put...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template