Home > php教程 > php手册 > php运行时动态创建函数的方法,php动态创建函数

php运行时动态创建函数的方法,php动态创建函数

WBOY
Release: 2016-06-13 09:12:01
Original
906 people have browsed it

php运行时动态创建函数的方法,php动态创建函数

本文实例讲述了php运行时动态创建函数的方法。分享给大家供大家参考。具体分析如下:

一般的语言函数必须定义了在运行,而php支持在运行时动态创建函数,下面是一个简单的范例,在运动时根据不同的条件创建函数$a

<&#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

希望本文所述对大家的php程序设计有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template