আগামী ১৫ ডিসেম্বর -২০১৭ তারিখ থেকে শুরু হচ্ছে পাঁচ মাস ব্যাপী Professional Web Design and Development with HTML, CSS PHP,MySQL,JavaScript, AJAX, JQUERY, Bootstrap and Live Project কোর্সের ৮৭ তম ব্যাচ এবং ২৬ ডিসেম্বর-২০১৭ তারিখ থেকে শুরু হচ্ছে চার মাস ব্যাপী Zend PHP-7 Certified PHP Engineering (Advance PHP) কোর্সের ৩৫ তম ব্যাচ। প্রত্যেকটি কোর্স এর ফী নির্ধারণ করা হয়েছে ৩০,০০০/= আগ্রহীদেরকে অতিসত্বর মাসুদ আলম স্যার এর সাথে যোগাযোগ করতে অনুরোধ করা যাচ্ছে। স্যার এর মোবাইল: 01722 81 75 91

PHP Control Structure Part I: PHP if, if-else statement

What’s the Control Structure on PHP?

PHP or any other programming language have control structure, that means control structure of program or code control the flow of program define the next staple.

What are the Control Structures on PHP?

List of Control Structures are below:

Control Structure List

  • Selection/Branching Statement

    • Conditional Statement
      • if
      • if…else
      • if…elseif/else if…n…else
      • switch Statement
    • Unconditional Statement
      • goto
      • Continue
      • break
      • return
  • Loops
    • for
    • while
    • do…while
    • foreach
  • File Inclusion
    • include
    • require
    • include_once
    • require_once

What is the if statement on PHP?

If there is an if statement in PHP or any programming language, will it not be possible to execute any part of the program, regardless of condition? It determines. Let’s say a little easier, suppose you go to the store to buy apple fruit, and decide if the apple does not get, then you will not come back or buy any other fruit instead. This image of real life is resolved with if statement in PHP or any programming language. Notice the following image:

If Statement in daily life

How does the If smentment work in PHP?

  • If statement in PHP will work, when any Logical Condition is true,
  • When the logical condition is false, the PHP or any other language Compiler blocks or skip on if statement.
  • If statement is also called one-way decision.

Flow Chart of the if statement on PHP

Notice the flowchart below to understand how a if statement work in PHP:

PHP If Statement Flowchart

What is the syntax of If statement?

if(condition)
{
here goes statements;
.
.
.
.
here goes statements;
}

Example 1:

<?php
$age = 18;
if($age > 17){
echo "you are eligible for voting ";
}
echo "\nThis is normal flow ";
?>

Example 2:

<?php
$age = 18;
if($age > 17 && $age<=30){
echo "you are eligible for apply BCS Job";
}
echo "\nThis is normal flow ";
?>

What is the if-else statement in PHP?

We know PHP or any Programming Language else statement is the opposite if statement fails to meet the condition or if the statement is not true, then whatever program is used to determine which part of it will be executed. Either, he is called else statement. Let’s say a little easier, suppose you go to the store to buy apple or orange fruit, and decide if Apple does not get, then instead of apple you will buy orange. This image of real life is resolved with an if-else statement in PHP or any programming language. Notice the following image:

php if else

  • When the logical condition of if statement is false in PHP, PHP Compiler if Statement will skip and run code between else statement block.

Flow Chart of the if-else statement in PHP

PHP If Else Flow Chart

What is the syntax of if-else statement?

if(condition)
{
here go statements....
}
else
{
here go statements....
}

Example 3:

<?php
$age=16;
if($age > 17)
{
print("\nyou are eligible for voting ");
}
else
{
print("\nSorry, you are not eligible for voting ");
}
echo "\nThis is normal flow ";

Example 4:

<?php
$age = 40;
if($age > 17 && $age<=30){
echo "you are eligible for apply BCS Job";
}
else{
print("\nSorry, you are not eligible for BCS Job");
}
echo "\nThis is normal flow ";
?>

Hi, My name is Masud Alam, love to work with Open Source Technologies, living in Dhaka, Bangladesh. I’m a Certified Engineer on ZEND PHP 5.3, I served my first five years a number of leadership positions at Winux Soft Ltd, SSL Wireless Ltd, Canadian International Development Agency (CIDA), World Vision, Care Bangladesh, Helen Keller, US AID and MAX Group where I worked on ERP software and web development., but now i’m a founder and CEO of TechBeeo Software Company Ltd. I’m also a Course Instructor of ZCPE PHP 7 Certification and professional web development course at w3programmers Training Institute – a leading Training Institute in the country.

Leave a Reply

Your email address will not be published. Required fields are marked *