www.webdeveloper.com
Results 1 to 2 of 2

Thread: php if else statement

  1. #1
    Join Date
    Jun 2006
    Location
    Boston, MA
    Posts
    383

    php if else statement

    im having trouble getting this to work..

    i have 1 variable to work with:

    <?=$club_info["year_introduced"]?>

    PHP Code:
    <?php 
     
    if  $club_info["year_introduced"] = null
       

    ?>
       HTML
    <?php 
       
    }
    else { 
    ?>
      HTML
    <?php  
    }
    ?>
    im not sure how to write it correctly. also, this is going to be within its own else statement. any help would be much appreciated. thanks.
    "Problems cannot be solved by the same level of thinking that created them.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,326
    Firstly: "=" is an assignment operator, while "==" is a comparison operator, and "===" is a type-sensitive comparison operator; so you'll want to use one of the latter two, depending on whether you only want to match if it is truly null, versus any value that is considered equivalent to null (empty string, 0, 0.0, or false, for instance).
    PHP Code:
    if($club_info["year_introduced"] == null)
    {
      
    // do stuff if it's null, false, "", 0, or 0.0
    }

    if(
    $club_info["year_introduced"] === null
    {
      
    // do stuff only if it is truly null

    For the latter case, you could also make use of the is_null() function.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles