PHP Programing language

adplus-dvertising
PHP If
Previous Home Next

If statement is using in PHP is very easy and similar to other programming languages, but for those who are not familiar with it, picture the following:

We want to using for if programming in PHP. If you have something to do the next day, say go to work, school, or an appointment, then you will set your alarm clock to wake you up. Otherwise, you will sleep in as long as you like.

The if statement is using in PHP Programming , let imagine that on AUGUST 15th you want to print out "Independence Day for INDIA" at the top of your personal web page. With the use of PHP if statements you could have this process automated, months in advance, occurring every year on AUGUST 15th.

This idea of planning for future events is something you would never have had the opportunity of doing if you had just stuck with HTML.

The "Independence Day for INDIA" example would be a little difficult for you to do right now, so let us instead start off with the basics of the if statement. The PHP if statement tests to see if a value is true, and if it is a segment of code will be executed. See the example below for the form of a PHP if statement.

<?php
$my_name = "Vikas";
if ( $my_name == "Vikas" ) 
	{
echo "MY friend are many <br />";
    }
echo "Welcome to my friend Circle!";
?>

Output:

MY friend are many!
Welcome to my friend Circle!

A False If Statement

Let us now see what happens when a PHP if statement is not true, in other words, false. Say that we changed the above example to:

<?php
$my_name = "Vinay";
if ( $my_name == "Hello dear friend" ) 
	{
echo "my friend is many !<br />";
    }
echo "Welcome to my homepage!";
?>

Output

Welcome to my homepage!

Here the variable contained the value "Vinay", which is not equal to "Hello dear friend". The if statement evaluated to false, so the code segment of the if statement was not executed. When used properly, the if statement is a powerful tool to have in your programming arsenal!

Previous Home Next