If else PHP

If else in PHP

There exist some conditions in “If Else Statements” to perform some specific tasks. All actions/functions totally depend on the conditions specified in “If Else Statement”. The condition can be True or False.

Example of If Else Statement

For example, in the figure, we can see the following real-life examples;

  1. If we obey God, We will get Heaven, Otherwise/Else we will get Hell.
  2. If someone fails in the exams, he will weep, Otherwise/Else he will be happy with a smile.
  3. If you work smart and work hard, you will get more money, Otherwise/Else you will get less money.
if else
Figure: if else

Let’s see an example of if else statement.

Program Statement

We want to write a program in PHP in which we will get a number, and then we will check that number is even number or odd number.


Get a number and divide the number with 2, if the remainder is zero, then the number is even, otherwise a number is an odd number.

Suppose number is 4, then 4 % 2 = 0, so 4 is even number. Similarly, if the number is 3, then 3/2 = 1, so the number is not even.


even odd number flow chart c,cpp, program
Figure: even odd number flow chart

If else Example in PHP

Prof. Fazal Rehman Shamil
Researcher, Publisher of International Journal Of Software Technology & Science ISSN: 2616-5325
Instructor, SEO Expert, Web Programmer and poet.
Feel free to contact.