call function php code example
Example 1: call javascript function from php
// The most basic method
<?php
echo '<script type="text/javascript">',
'someJsFunc();',
'</script>';
?>
// However, if what you are trying to achieve requires more complexity,
// You might be better off adding the V8JS module, see link below
Example 2: how to define function in php
<?php
function writeMsg() {
echo "Hello world!";
}
writeMsg();
?>
Example 3: call php function in js
<script>
var phpadd= <?php echo add(1,2);?>
var phpmult= <?php echo mult(1,2);?>
var phpdivide= <?php echo divide(1,2);?>
</script>
Example 4: execute function php
function functionName() {
}
functionName();
Example 5: php functions
#functions
<?php
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>";
?>