/    Sign up×
Community /Pin to ProfileBookmark

What is this shot hand for an If statement

? ‘succeeded’ : ‘failed’;

My thinking is if succeeded : or failed am I right????

I searched on google, and asked a few administrators but they havent seen it before.

Please help.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guySep 21.2005 — 1 == 2 ? echo "I cant count" : echo "I can count";
Copy linkTweet thisAlerts:
@solidaritiauthorSep 21.2005 — This doesnt seem to work, it says that there is an unexpected T_ECHO I've tried putting a semi colon between the two echo statements and : but that doesnt seem to work.

So its like a shortened if statement then?
Copy linkTweet thisAlerts:
@NogDogSep 21.2005 — [code=php]
echo (1 == 2) ? "I can't count" : "I can count";
[/code]
Copy linkTweet thisAlerts:
@NogDogSep 21.2005 — PS: It is called the "ternary operator". More info on this page: http://www.php.net/manual/en/language.operators.comparison.php
The expression [i](expr1) ? (expr2) : (expr3)[/i] evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.[/quote]
Copy linkTweet thisAlerts:
@Stephen_PhilbinSep 21.2005 — Aye, weirdly, using the sort-hand if structure seems to return the selected result rather than execute it as a standard if structure would do.
Copy linkTweet thisAlerts:
@felgallSep 21.2005 — A = B ? C : D;

is equivalent to

if (? {A = C;} else {A = D;}
Copy linkTweet thisAlerts:
@pyroSep 21.2005 — Aye, weirdly, using the sort-hand if structure seems to return the selected result rather than execute it as a standard if structure would do.[/QUOTE]You are only supposed to use the ternary opperator when you want to return a value. ?
Copy linkTweet thisAlerts:
@SpectreReturnsSep 22.2005 — And by return he doesn't mean using 'return'. He means returning a value to use later on in the script (but can be used for 'return' if you want).

[code=php]
$test = ((true) ? "true" : "false"); // good use
((true) ? echo("hello") : print("sup")); // Bad use
[/code]
Copy linkTweet thisAlerts:
@kazotechSep 22.2005 — normal if statement

if ($a == $b)

{

echo "THIS IS VALID";

}

else

{

echo "THIS IS NOT VALID":

}

short hand for writing if statement

echo ($a==$b) ? "THIS IS VALID" : "THIS IS NOT VALID" ;
×

Success!

Help @solidariti spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...