how to call function in php code example
Example 1: call javascript function from php
<?php
echo '<script type="text/javascript">',
'someJsFunc();',
'</script>';
?>
Example 2: function php
function functionName() {
}
Example 3: how to define function in php
<?php
function writeMsg() {
echo "Hello world!";
}
writeMsg();
?>
Example 4: execute function php
function functionName() {
}
functionName();
Example 5: how to call js function from php
<?php
if(your condition){
echo "<script> window.onload = function() {
yourJavascriptFunction(param1, param2);
}; </script>";
?>
Example 6: 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>";
?>