scriptygoddess

05 Nov, 2004

PHP: simple logic statement

Posted by: Jennifer In: Lessons learned

I'm tired of searching for the correct syntax everytime I wan to use this line… if you're doing a simple one line "if" statement, you can use a "ternary conditional operator" – for example:

echo $variable == 'value' ? 'print if true' : 'print if false';

Related posts:

  1. Simple Shortcode for Line Breaks One kind of funny thing with WordPress is that entering...
  2. Conditionally change path to HTTPS One of my clients had set it up so that...

Related posts brought to you by Yet Another Related Posts Plugin.

3 Responses to "PHP: simple logic statement"

1 | Mischievous Ramblings » PHP: Ternary Operator

November 20th, 2004 at 5:56 am

Avatar

[...] 2004.11.19 PHP: Ternary Operator 9:54 pm in Programming  | scriptygoddess provides a quick note reminding us how the ternary o [...]

2 | Jonathan Johnson

November 5th, 2004 at 10:10 pm

Avatar

Ah, the ternary operator. Just remember this. The question mark comes after the item in question — Is __ true ? Yes : No;

It's the only way I can remember it ;)

3 | Michael Moncur

November 6th, 2004 at 12:03 am

Avatar

Don't you need parentheses around the condition? Or they optional in PHP?

Featured Sponsors


  • Michael: You can use get_header(2) in your case. The filename of your custom header has to be header-2.php. The problem with include(your_file.php) is, all
  • cliff: hi wonder if you can help me, pls i designed www.kouga.mobi using dreamweaver CS3 and now want to make the phonenumbers into links so that if you
  • jerey: how do i rewrite this because it tried RewriteEngine on #Options +FollowSymlinks RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FIL

About


Advertisements