php call a function code example
Example 1: how to define function in php
<?php
function writeMsg() {
echo "Hello world!";
}
writeMsg();
?>
Example 2: php call dynamic function
$vFn = "Login";
$vFn();
call_user_func($vFn, $vars);
abstract class mBase {
public function main() {
.....
}
}
class mA extends mBase {
public function main() {
parent->main();
.....
}
}
class mB extends mBase {
public function main() {
parent->main();
.....
}
}
function runMM(mBase $module) {
$module->main();
}
$m = 'mB';
runMM ($m);
Example 3: php functions
#functions
<?php
#function - a block of code that can be repeatedly called
function simpleFunction(){
echo 'Hello John';
}
simpleFunction();
function sayHello($name = " you out there!"){
echo "<br>and<br> Hello $name<br>";
}
sayHello('John');
sayHello();
function addNumbers($num1, $num2){
return $num1 + $num2;
}
echo addNumbers(2,3);
$myNum = 10;
function addFive($num){
$num += 5;
}
function addTen(&$num) {
$num += 10;
}
addFive($myNum);
echo "<br>Value: $myNum<br>";
addTen($myNum);
echo "Value: $myNum<br>";
?>