Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-02-2010
Member
 
Join Date: Jul 2006
Posts: 286
How to use If statement in PHP?

Hi friends,
I am new to PHP. Before this I have studied the C, C++ and Visual Basic. We were having that subjects in junior college. I guess that the concept of the if statement in PHP should be very much similar to the same statement in C or C++ languages. But I don't know the coding that can be used in the PHP. So please help me..!! Tell me how to use If statement in PHP? Any coding related to same would be appreciable.
__________________
IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....
Reply With Quote
  #2  
Old 09-02-2010
Member
 
Join Date: Mar 2008
Posts: 672
Re: How to use If statement in PHP?

The logic of the if statement is same in every language. The if statement is a conditional statement. Conditional statements are used to perform different actions based on different conditions. When you want to perform different actions for different decisions, you have to use the conditional statements like the if statement. The if statement is used to execute some code only if a specified condition is true. Hope that you get the point of using the if statement.
Reply With Quote
  #3  
Old 09-02-2010
Member
 
Join Date: Nov 2008
Posts: 1,192
Re: How to use If statement in PHP?

The following is an example of the if statement. I have also provided you the syntax so that it can be easy for you to use the if statement. Here is a syntax :
Code:
if (condition) code to be executed if condition is true;
And here is an example of the same :
HTML Code:
<html>
<body>

<?php
$d=date("D");
if ($d=="Sat") echo "Enjoy the Party!";
?>

</body>
</html>
Reply With Quote
  #4  
Old 09-02-2010
Member
 
Join Date: Nov 2008
Posts: 996
Re: How to use If statement in PHP?

Many times you want to display more than one line in a coder. If you want more than one line should be executed if a condition is true/false, then you should include the curly braces in which the lines must be enclosed. I have done the same thing in the given example :
HTML Code:
<html>
<body>

<?php
$d=date("D");
if ($d=="Mon")
  {
  echo "Welcome!!<br />";
  echo "Lets Start the Project!!";
  echo "Collect your Salary!!";
  }
?>

</body>
</html>
Reply With Quote
  #5  
Old 09-02-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: How to use If statement in PHP?

You can also use the if statement, for checking the false statements. You can check the below example in which the if statement is used for the false statement :
PHP Code:
$my_name "differentcar";

if ( 
$my_name == "differentcar" ) {
    echo 
"Your name is differentcar!<br />";
}
echo 
"Welcome to my homepage!"
The output will be
Code:
Welcome to my homepage!
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use If statement in PHP?"
Thread Thread Starter Forum Replies Last Post
SQL statement problem in C# AMISH Software Development 4 01-06-2010 01:17 PM
How to use Else and Else If Statement in PHP? Orton Software Development 5 05-03-2010 06:49 AM
HTML if else statement Darthmouth Software Development 3 02-09-2009 06:02 PM
If Statement in HTML Beatrisa Software Development 3 07-08-2009 02:33 PM
What is the difference between while statement & do statement? Athos Software Development 4 25-02-2009 08:52 PM


All times are GMT +5.5. The time now is 08:24 PM.