Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Operator ternary
Look at the operator ternary:

$flag = true;

($flag)?($a = "yes"):($a = "no");

Now i want to have multiple statements in my operator ternary something like
(does not work!!!):

($flag)?($a = "yes";$b="yes"):($a = "no";$b="no");

One way to make this work is:

($flag)?($a = "yes" and $b="yes"):($a = "no" and $b="no"); but to me this is
not logical.

Does somebody have any ideas about this?

regards,

Marcel



Report this thread to moderator Post Follow-up to this message
Old Post
Marcel
06-02-05 01:58 PM


Re: Operator ternary
Marcel said the following on 02/06/2005 10:21:
> Look at the operator ternary:
>
> $flag = true;
>
> ($flag)?($a = "yes"):($a = "no");
>
> Now i want to have multiple statements in my operator ternary something li
ke
> (does not work!!!):
>

The ternary operator is not designed to execute code. It's designed for
uses such as:

$a = $flag : "yes" : "no";

i.e. assigning a value dependent on the logical state of $flag. It just
so happens that your code above works, because '$a = "yes"' evaluates to
a value, and so can be used in the ternary operator.

Why not just use if? That's what it's there for! And it's far more
obvious what's going on than trying to cram a load of code onto one line.

if ($flag)
{
..
}
else
{
..
}


--
Oli

Report this thread to moderator Post Follow-up to this message
Old Post
Oli Filth
06-02-05 01:58 PM


Re: Operator ternary
"Oli Filth" <catch@olifilth.co.uk> schreef in bericht
news:bvAne.4425$cN2.1263@newsfe4-gui.ntli.net...
> Marcel said the following on 02/06/2005 10:21: 
>
> The ternary operator is not designed to execute code. It's designed for
> uses such as:
>
> $a = $flag : "yes" : "no";
>
> i.e. assigning a value dependent on the logical state of $flag. It just so
> happens that your code above works, because '$a = "yes"' evaluates to a
> value, and so can be used in the ternary operator.
>
> Why not just use if? That's what it's there for! And it's far more obvious
> what's going on than trying to cram a load of code onto one line.
>
> if ($flag)
> {
> ...
> }
> else
> {
> ...
> }
>
>

Ok thanks that what i was thinking too!

Regards,

Marcel



Report this thread to moderator Post Follow-up to this message
Old Post
Marcel
06-02-05 01:58 PM


Re: Operator ternary
"Marcel" <sorryafraidofspam@nospam.com> wrote in message
news:de175$429ecf8b$3e3a8507$17716@news.versatel.nl...
> Look at the operator ternary:
>
> $flag = true;
>
> ($flag)?($a = "yes"):($a = "no");
>
> Now i want to have multiple statements in my operator ternary something
> like (does not work!!!):
>
> ($flag)?($a = "yes";$b="yes"):($a = "no";$b="no");
>
> One way to make this work is:
>
> ($flag)?($a = "yes" and $b="yes"):($a = "no" and $b="no"); but to me this
> is not logical.
>
> Does somebody have any ideas about this?
>


You're supposed to use it like this:
$a = $flag ? 'yes' : 'no';
$b = $flag ? 'yes' : 'no';
$c = $flag ? 'michael' : 'knight';
etc.. Or like Oli said, use if statement...

--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com



Report this thread to moderator Post Follow-up to this message
Old Post
Kimmo Laine
06-02-05 01:58 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:42 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.