Results 1 to 5 of 5

Thread: How to use If statement in PHP?

  1. #1
    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....

  2. #2
    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.

  3. #3
    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>

  4. #4
    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>

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    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!

Similar Threads

  1. SQL statement problem in C#
    By AMISH in forum Software Development
    Replies: 4
    Last Post: 01-06-2010, 01:17 PM
  2. How to use Else and Else If Statement in PHP?
    By Orton in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 06:49 AM
  3. HTML if else statement
    By Darthmouth in forum Software Development
    Replies: 3
    Last Post: 02-09-2009, 06:02 PM
  4. If Statement in HTML
    By Beatrisa in forum Software Development
    Replies: 3
    Last Post: 07-08-2009, 02:33 PM
  5. Replies: 4
    Last Post: 25-02-2009, 08:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,635,747.82226 seconds with 17 queries