Calling Functions Dynamically : Dynamic Function « Functions « PHP






Calling Functions Dynamically

<!--
   In PHP, you can call functions dynamically

   1.   Declare a function
   2.   Then declare a variable and assign the function name to the variable (as a string)
   3.   Then use the variable as a function
-->

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

           
       








Related examples in the same category

1.Calling a Function Dynamically
2.Calling Variable Functions
3.Calling a Function Dynamically
4.Creating Dynamic Functions
5.return the function name from a function call or calculation
6.Variable function example
7.Variable Function Names
8.Using a variable function determined by some input variable
9.String Manipulation
10.Using Arrays of Lambda Functions