Home >Backend Development >PHP Problem >How to dynamically call functions in php

How to dynamically call functions in php

coldplay.xixi
coldplay.xixiOriginal
2020-08-05 11:34:243752browse

How to dynamically call a function in php: first define a function; then assign the function name or string to a variable; finally use the variable name instead of the function name to dynamically call the function.

How to dynamically call functions in php

How to dynamically call functions in php:

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

The detailed code is as follows:

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

Related video recommendations: PHP programming from entry to proficiency

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