Home > Backend Development > PHP Tutorial > php dynamically creates functions at runtime

php dynamically creates functions at runtime

WBOY
Release: 2016-07-25 08:43:31
Original
967 people have browsed it

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

  1. if (count($_POST) > 0) {
  2. $prepped = create_function('$a', 'return trim($_POST[$a]);');
  3. }
  4. elseif (count($_GET) > 0 ) {
  5. $prepped = create_function('$a', 'return strtoupper($_GET[$a]);');
  6. }
  7. else {
  8. $prepped = create_function('$a', 'return false;') ;
  9. }echo $prepped('file');
  10. ?>
Copy code

php


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