Articles → PHP → Functions in PHP

Functions in PHP






















Software requirement









Technical knowledge





What are functions in PHP?





Syntax


function function_name(parameters separated by comma) {
 // Code
}



Example




<?php
   function Message()
   {
      echo("Hello");
   }
   
   Message();
?>





Function with arguments




<?php
   function Message($name)
   {
      echo("Hello ".$name);
   }
   
   Message("Gyan");
?>





Default argument in PHP




<?php
   function Message($name="Gyan")
   {
      echo("Hello ".$name);
   }
   
   Message();
?>





Return values in PHP




<?php
   function Sum($num1, $num2)
   {
      return $num1 + $num2;
   }
   
   echo(Sum(1,2));
?>





Posted By  -  Karan Gupta
 
Posted On  -  Saturday, November 01, 2014

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250