Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
PHP If Statement
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Tutorials
  3. PHP If Statement

PHP Tutorial

Basic PHP Fundamentals

  • PHP Tutorial Content
  • PHP Introduction
  • PHP History
  • Uses of PHP
  • PHP Features
  • What Is PHP
  • PHP Installation And Software Requirements
  • How To Install Wamp Server
  • How To Install Xampp Server
  • Php Syntax
  • PHP Variables
  • PHP Data Types
  • PHP Constants
  • PHP Echo And Print
  • PHP Operators
  • PHP Assignment Operators
  • PHP String And Logical Operators
  • Operators Categories
  • PHP Comments
  • PHP $ And $$ Variables
  • Super Global Variables

PHP Control Statement

  • PHP Control Structure
  • PHP If Statement
  • If Elseif Statement In PHP
  • Switch Statement In PHP
  • Break Statement In PHP
  • If Elseif Else Statement
  • Continue Statement In PHP

Php Loops

  • What Is Loop
  • For Loop In PHP
  • PHP Foreach Loop
  • PHP While Loop
  • Do While Loop

PHP Arrays

  • PHP Arrays
  • Indexed Arrays
  • Associative Array
  • Multidimensional Arrays
  • Array Functions
  • Array Constants
  • List of Array Functions
  • Array Functions First Exercise

Php String

  • String In PHP
  • PHP String Functions

PHP Functions

  • PHP Functions
  • PHP Parameterized Function
  • PHP Call By Value
  • Call By Reference In PHP
  • Default Argument Values Function In PHP
  • Variable Argument Function In PHP
  • Recursive Function In PHP
  • Math Function In PHP
  • Math Function Examples

PHP Form

  • Form Handling In PHP

PHP Include

  • Include File In PHP

PHP State Management

  • Cookies In PHP
  • Session In PHP

PHP File System

  • File Handling In PHP
  • Open Files In PHP
  • Read Files In PHP
  • Write Files In PHP
  • Delete Files In PHP
  • Append To Files In PHP

PHP Upload & Download

  • File Upload In PHP
  • Download File In PHP

PHP Mail System

  • Mail System In PHP
  • Mail With Attachment In PHP

Basic PHP Program

  • Php Programs
  • Sum Of Digits
  • PHP Even Odd Program
  • Prime Number Program
  • Table Of Number Program
  • Factorial Of A Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series

PHP If Statement

Summary: Php If Statement

if statement in PHP

  • The if Statement is the simplest conditional statements.
  • In if  Statements Output will appear when only Condition must be true.
  • If Statement works  much like the English language statement, “if X happens, then do Y.”
if statement

Syntax

<?php
if (condition) {
    //code to be executed if condition is true;
}
?>

Example 1: Write a program to check even number.(Number entered by user)

<?php   
if(isset($_GET["Usersave"]))  
{
  $numberUser=$_GET["user_number"];
  if($numberUser%2==0)
  {
   echo $numberUser."is even number";
  }
}
?>
<html>	
<head>
<title>Check even or odd Number</title>
</head>	
<body>
<form method="get">  
Enter Your number<input type="text" name="user_number"/><br/>	      
<input type="submit" value="check number" name="Usersave"/>
</form>
</body>
</html>

Output :  10 is Even number

Example 2: Write a program to check the given number is Positive

example to check if given number is greater than 0 then show notification
message number is positive.

<?php
$num=$_POST["unumber"];
if($num>0) 
{	   
echo $num." is positive number";		 
}	 
?>
<html>	
<head>
<title>Check Positive Number</title>
</head>
<body>	
<form method="post">	   
Enter Your number<input type="text" name="unumber"/><br/>	   	    
<input type="submit" value="check number"/>	 
</form>
</body>
</html>

Output :  10 is positive number

Example 3: Write a program to find the sum of even number between 1 to 100

 

<?php
$sum=0;
for($i=1;$i<=100;$i++) 
{	
if($i%2==0)		 
{		
$sum=$sum+$i;		
}	
}	
echo $sum;
?>

Output: 2550

in the above example,
whole program are in PHP script. Here we want to sum of even no.
We declare a variable($sum) initialize its value = 0.
For loop is used to check value from 1 to 100. The condition that declare inside the if check the number is even or not.
if the no is even, statement will execute and print sum of all even no those exist between 1 to 100.
Initially $sum value=0. after check the even number condition.it store the even no in variable ( $i) and it sum with ($sum).
again and again it check the even number condition and calculate the sum.

Series: PHP Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
if statement in PHP control statement if condition in php conditional Statement php conditional operator php if statement multiple conditions php if else shorthand php endif

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.