PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Wed Nov 05, 2003 3:00 am
Code: Select all
ini_get('display_errors') == '1' ? 'On' : 'Off'
Hey Mac, or anyone - got a tutorial on that string's syntax? I still don't really understand it. From how i look at it, it's like if 1 is returned from ini_get('display_errors') then............*falls off*
-Nay
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Wed Nov 05, 2003 5:40 am
Also mentioned as 'Alternate Syntax' to if-then-else.
Same thing as:
Code: Select all
$var = ini_get('display_errors');
if ($var == '1') {
echo 'On';
} else {
echo 'Off';
}
...but as you see, much shorter.
Same idea can be used for example coloring lines in <table>'s...
Code: Select all
$i = 'red';
whie (something to loop) {
$i = ($i == 'red' ? 'blue' : 'red'); // set $i to 'the other value'
echo '<td bgcolor="'.$i.'">foo</td>';
}...just to mention other usages.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Nov 05, 2003 5:49 am
[php_man]language.operators.comparison[/php_man]
The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Nov 05, 2003 6:03 am
I split this from the other topic before it got too off-topic
.
Mac
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Wed Nov 05, 2003 10:40 pm
Yay! Thanks guys...
Now that's one more piece of syntax in my head
, hope I just remember to use it when a time comes
.
-Nay
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Wed Nov 05, 2003 10:45 pm
Hate it personally, on the grounds that it's less clear. I'd recommend avoiding it but everyone's got their own style.