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
- 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');
- ?>
Copy code
|