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
<?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'); ?>
I hope this article will be helpful to everyone’s PHP programming design.