Skip to main content

//Function:-Arthmatic Operation

Function:-Arthmatic Operation


  1.  <?php
  2. //Function Arthmatic Operation

  3. //Function Definition

  4. //Addition
  5. function add($a ,$b)  //function name must start with letter or underscore.
  6. {
  7. $c = $a + $b;
  8. echo "the addtion is:".$c."<br>" ;
  9. }
  10. add (20, 40);   //Function Call:- You can many times call function.
  11. add (45, 45);  //you can add many argumentsas you want.

  12. //Subtraction
  13. function sub($a, $b)
  14. {
  15. $c = $a - $b;
  16. echo "the subtraction is ".$c."<br>";
  17. }
  18. sub (45, 25); //45, 25 this value store in 'a' and 'b', then execute operation "45 - 25 = 20".

  19. //Division
  20. function div($a ,$b)
  21. {
  22. $c = $a / $b;
  23. echo "the division is:" .$c. "<br>";
  24. }
  25. div (100, 4);

  26. //Multiplication
  27. function multi($a ,$b)
  28. {
  29. $c = $a - $b;
  30. echo "the multipication is:" .$c. "<br>"; //"echo" use for print line.
  31. }
  32. multi(50, 20);

  33. //Modulus
  34. function mod($a ,$b)
  35. {
  36. $c = $a % $b;
  37. echo "the moddulos is:" .$c. "<br>"; //"<br>" use for linebreak. 
  38. }
  39. mod(50, 5);
  40.  ?>



👉Execute👈


//Output

/*

the addtion is:60

the addtion is:90

the subtraction is 20

the division is:25

the multipication is:30

the moddulos is:0

*/




                                                                   //ThE ProFessoR