Advertisement
sayful

PHP Function

Aug 6th, 2014
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * Function without parameters
  5.  */
  6. //create function
  7. function function_name(){
  8.     echo 'This is a Function<br><hr>';
  9. }
  10. //get the function
  11. function_name();
  12.  
  13. /*
  14.  * Function with parameters
  15.  */
  16. function function_parm($parm1,$parm2,$parm3){
  17.     echo ($parm1 + $parm2) - $parm3;
  18. }
  19.  
  20. function_parm(2, 9, 1);
  21. echo '<br><hr>';
  22.  
  23. /*
  24.  * Function with return value
  25.  */
  26. function function_return($a, $b, $c){
  27.     return ($a + $b) - $c;
  28. }
  29.  
  30. echo function_return(10, 10, 7);
  31. echo '<br><hr>';
  32.  
  33. /*
  34.  * Function with array
  35.  */
  36. function func_arr($param) {
  37.     $sum = 0;
  38.     $mul = 1;
  39.     foreach ($param as $new){
  40.         $sum += $new;
  41.         $mul *= $new;
  42.     }
  43.     return array($sum, $mul);
  44. }
  45.  
  46. $result = func_arr(array(2,4,4));
  47.  
  48. echo 'Sum is '.$result['0'].'<br>';
  49. echo 'Mul is '.$result['1'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement