Home >Backend Development >PHP Tutorial >php运行时动态创建函数的方法_php技巧

php运行时动态创建函数的方法_php技巧

WBOY
WBOYOriginal
2016-05-16 20:20:47977browse

本文实例讲述了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;>

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

Statement:
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