• home
  • forum
  • my
  • kt
  • download
  • The Ternary Operator: Like If Statements, Just Simplified!

    Author: 2008-08-26 11:14:05 From:

    Ternary Conditionals are one of those things in php that can save some time when writing code and possibly make your code easier to read. I think many people don't use them because they look a little strange ( at least thats what happened to me )

    PHP Code:
    if ($iExample == 1
    {
    $bVariable true;
    } else {
    $bVariable false;

    In the example above, if the statement is true then, it will set $bVariable to true or else it will set it to false. This is a regular conditional statement where if a condition is true something happens or else (if the condition is false) other thing happen. Conditional statements like that could be easily handled with a ternary conditional:

    PHP Code:
    $bVariable = ($iExample == 1) ? true false
    As you can see the syntax of the Ternary Conditional is pretty simple and looks good as its fits all in one line.

    PHP Code:
    Variable = (condition) ?  its true its false

    Well i may not be the most adequate to write a tutorial, but i hope this helps someone

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (12)
      Discussion Boards (8)
      E Commerce (8)
      Email Systems (13)
      Error Handling (7)
      File Manipulation (24)
      Flash and PHP (6)
      Form Processing (19)
      Guestbooks (12)
      Image Manipulation (21)
      Installing PHP (7)
      Introduction to PHP (23)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (53)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot