Home > Backend Development > PHP Tutorial > How to dynamically create functions when php is running, php dynamically create functions_PHP tutorial

How to dynamically create functions when php is running, php dynamically create functions_PHP tutorial

WBOY
Release: 2016-07-13 10:03:29
Original
785 people have browsed it

How to dynamically create functions when php is running, php dynamically create functions

The example in this article describes the method of dynamically creating functions when php is running. Share it with everyone for your reference. The specific analysis is as follows:

General language functions must be defined at runtime, and PHP supports dynamic creation of functions at runtime. The following is a simple example to create a function $a according to different conditions during exercise

<&#63;php
if (count($_POST) > 0) {
  $prepped = create_function('$a', 'return trim($_POST[$a]);');
}
elseif (count($_GET) > 0) {
  $prepped = create_function('$a', 'return strtoupper($_GET[$a]);');
}
else {
  $prepped = create_function('$a', 'return false;');
}echo $prepped('file');
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968264.htmlTechArticleHow to dynamically create functions during PHP runtime, PHP dynamically create functions. This article describes how to dynamically create functions during PHP runtime. method. Share it with everyone for your reference. The specific analysis is as follows:...
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