Calling Variable Functions : Dynamic Function « Functions « PHP






Calling Variable Functions

 
<?php 
function addvalues ($firstvalue = 0, $secondvalue = 0){ 
    return $firstvalue + $secondvalue; 
} 
function subtractvalues ($firstvalue = 0, $secondvalue = 0){ 
    return $firstvalue - $secondvalue; 
} 
function multiplyvalues ($firstvalue = 0, $secondvalue = 0){ 
    return $firstvalue * $secondvalue; 
} 
$firstvalue = 10; 
$secondvalue = 3; 
$whattodo = "addvalues"; 

echo $whattodo($firstvalue, $secondvalue) . "<br />"; 

$whattodo = "subtractvalues"; 
echo $whattodo($firstvalue, $secondvalue) . "<br />"; 
?>
  
  








Related examples in the same category

1.Calling Functions Dynamically
2.Calling a Function Dynamically
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