0) {...}"; 3. Dynamically create methods through "create_function()" statements That’s it."/> 0) {...}"; 3. Dynamically create methods through "create_function()" statements That’s it.">
Home > Article > Backend Development > How to dynamically create methods in php
php dynamic creation method: 1. Create a PHP sample file; 2. Create conditional statements through "if (count($_POST) > 0) {...}"; 3. Through "create_function" ()" statement can dynamically create a method.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
How to dynamically create methods in php?
How to dynamically create functions during PHP runtime
General language functions must be defined at runtime, and PHP supports dynamically creating functions at runtime, as follows It is a simple example that creates functions according to different conditions during exercise $a
<?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'); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to dynamically create methods in php. For more information, please follow other related articles on the PHP Chinese website!