Addition and subtraction program in php

There are three methods to subtract two numbers:

  • Subtraction in simple code in PHP
  • Subtraction in form in PHP
  • Subtraction without using arithmetic operator [+].

Subtraction in Simple Code

Subtraction of two numbers 30 and 15 is shown.

Example:

Output:

Subtraction in Form

By inserting values in the form two numbers can be subtracted.

Example:

Output:

Subtraction in Form without [-] Operator

By inserting values in the form two numbers can be subtracted but without using [-] operator.

Example:

Output:

15357

For Videos Join Our Youtube Channel: Join Now

Feedback

  • Send your Feedback to [email protected]

Help Others, Please Share

There are three methods to add two numbers:

  • Adding in simple code in PHP
  • Adding in form in PHP
  • Adding without using arithmetic operator [+].

Adding in Simple Code

Addition of two numbers 15 and 30 is shown here.

Example:

Output:

Adding in Form

Two numbers can be added by passing input value in the form.

Example:

Output:

Adding in Simple Code

Two numbers can be added by passing input value in the form but without using [+] operator.

Output:

For Videos Join Our Youtube Channel: Join Now

Feedback

  • Send your Feedback to [email protected]

Help Others, Please Share

Let’s see how to write a simple PHP program to do Addition, Subtraction, Multiplication & Division kind of a Simple PHP Calculator. Let’s start with a PHP function then I will show you a complete demo script as well.

The below snippet shows you how to perform mathematical operations in PHP.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

So, it’s pretty simple to do the mathematical operation in PHP. Now let’s create a function and use the same logic with a Switch case so we can call the function and pass different values to perform different mathematical operations.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

I hope you have a clear idea now how we can do mathematical operations such as Addition, Subtraction, Multiplication & Division using the PHP language.

Let me give you a complete demo of this script with an HTML form so you can copy & paste it into a PHP file to execute and test it.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

Addtion,Substraction,Divide&Multiplication using PHP!

            

                

                    Addition, Subtraction,Multiplication&Division using PHP!

                    

                    

                        Value1:

                    

                    

                        

Chủ Đề