Home  >  Article  >  Backend Development  >  How to dynamically call functions in php

How to dynamically call functions in php

王林
王林Original
2020-07-17 15:50:504401browse

The method of dynamically calling functions in php is: 1. Define a function, such as [function addition($a,$b)]; 2. Assign the function name (string) to a variable, such as [ $result="addition"]; 3. Use variable names instead of function names to dynamically call functions.

How to dynamically call functions in php

Steps to dynamically call functions:

(Recommended tutorial: php tutorial)

1 , define a function;

2. Assign the function name (string) to a variable;

3. Use the variable name instead of the function name to dynamically call the function.

Code implementation:

<?php
 function addition ($a, $b){
   echo ($a + $b), "\n";
 }
 $result = "addition";
 $result (3,6);
?>

The above is the detailed content of How to dynamically call functions in php. For more information, please follow other related articles on the PHP Chinese website!

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