Answers for "php function use"

PHP
8

how to define function in php

<?php
function writeMsg() {
    echo "Hello world!";
}

writeMsg(); //call the function
?>
Posted by: Guest on April-17-2020
13

function php

function functionName() {
    //code to be executed;
}
Posted by: Guest on November-28-2019
2

php functions parameters

// functions require 'function' keyword
// separate the parameters with a comma
function addFunction($num1, $num2) {
	$sum = $num1 + $num2;
	echo "Sum of the two numbers is : $sum";
}

addFunction(1, 2); // echoes: Sum of the two numbers is : 3
Posted by: Guest on July-26-2020
0

php function

<html>
   
   <head>
      <title>Writing PHP Function with Parameters</title>
   </head>
   
   <body>
   
      <?php
         function addFunction($num1, $num2) {
            $sum = $num1 + $num2;
            echo "Sum of the two numbers is : $sum";
         }
         
         addFunction(10, 20);
      ?>
      
   </body>
</html>
Posted by: Guest on March-02-2021
2

php functions

#functions

<?php
    #function - a block of code that can be repeatedly called

    /*
    How to format functions
    1. Camel Case myFunction()
    2.Lower case with underscore my_function()
    3. Pascal Cae - MyFunction() usally used with classes
    */
    function simpleFunction(){
        echo 'Hello John';

    }
    //Run the function like so
    simpleFunction();

    //function with param
    function sayHello($name = " you out there!"){
        echo "<br>and<br> Hello $name<br>";
    }
    sayHello('John');
    sayHello();

    //Reurn Value
    function addNumbers($num1, $num2){
        return $num1 + $num2;
     }
     echo addNumbers(2,3);

     // By Reference

     $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>";


?>
Posted by: Guest on May-13-2020
0

php function use

// Inherit $message
$example = function () use ($message) {
    var_dump($message);
};
$example();
Posted by: Guest on August-13-2021

Code answers related to "php function use"

Browse Popular Code Answers by Language