How to create a function from a string in php_PHP tutorial

WBOY
Release: 2016-07-13 10:03:31
Original
923 people have browsed it

How to create a function from a string in php

This article mainly introduces how to create a function from a string in php, involving the usage skills of strings and create_function functions in php. Friends in need can refer to it

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:

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/968656.htmlTechArticleHow to create functions from strings in php. This article mainly introduces how to create functions from strings in php, involving Tips on using strings and create_function functions in php, friends who need it can...
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