Re: [PHP] Like ternary but without the else.

2005-02-25 Thread Justin Lilly
This should do the trick:

$something ? $this=$that

-justin


On Fri, 25 Feb 2005 10:36:36 -0800, Chris W. Parker
[EMAIL PROTECTED] wrote:
 Hello,
 
 I couldn't find this anywhere on google or PHP's site but I'm pretty
 sure there's an answer to it.
 
 How can I turn the following into something that resembles the ternary
 operator?
 
 ?php
 
   if($something)
   {
 $this = $that;
   }
 
 ?
 
 I seem to remember it looking something like:
 
 ?php
 
   $this = ($something) || $that;
 
 ?
 
 Although this isn't syntactically wrong, i.e. no errors, it did not do
 what I hoped it would do. (What it does is assign 1/true.)
 
 Thanks!
 Chris.
 
 p.s. No need to respond if your suggestion is:
 
 ?php
 
   if($something) { $this = $that; }
 
 ?
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
Justin Lilly
University of South Carolina

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Like ternary but without the else.

2005-02-25 Thread Brian V Bonini
On Fri, 2005-02-25 at 13:36, Chris W. Parker wrote:
 How can I turn the following into something that resembles the ternary
 operator?
 
 ?php
 
   if($something)
   {
 $this = $that;
   }
 
 ?


$this = (isset($something)) ? $something : $that;

The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1
evaluates to TRUE, and expr3 if expr1 evaluates to FALSE. 

-- 

s/:-[(/]/:-)/g


BrianGnuPG - KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
==
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
Key Info: http://gfx-design.com/keys
Linux Registered User #339825 at http://counter.li.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Like ternary but without the else.

2005-02-25 Thread rich
I couldn't find this anywhere on google or PHP's site but I'm pretty sure
there's an answer to it.

How can I turn the following into something that resembles the ternary
operator?

?php

  if($something)
  {
$this = $that;
  }

?


is this what you're after?

$this = ($something ? $that : $this) 

rich

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Like ternary but without the else.

2005-02-25 Thread Jochem Maas
Chris W. Parker wrote:
Hello,
I couldn't find this anywhere on google or PHP's site but I'm pretty
sure there's an answer to it.
How can I turn the following into something that resembles the ternary
operator?
write an extension to the php engine? don't think it exists.
?php
  if($something)
  {
$this = $that;
  }
just do:
if ($something) $this = $that;
..personally I don't like braceless if statements.
?
or one of these might work for you;
$this = ($something) ? $that: $this; // if $this already exists.
or
$this = ($something) ? $that: null; // if $this does not exist and your happy 
to use is_null()
I seem to remember it looking something like:
?php
  $this = ($something) || $that;
?
btw your not using 'this' as an actual variable name are you?
(unless its on purpose for doing bad(tm) things in php4 :-)
Although this isn't syntactically wrong, i.e. no errors, it did not do
what I hoped it would do. (What it does is assign 1/true.)
what it does is assign the result of the expression (($something) _or_ 
$that)
to $this.
if either of those equate to true (dont forget php autotypecasts),
then the expression is true, its a boolean 'or' so it will always make
$this a boolean, which print as:
php -r 'echo true;' // echos 1
php -r 'echo false;'// echos ''

Thanks!
Chris.
p.s. No need to respond if your suggestion is:
?php
  if($something) { $this = $that; }
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Like ternary but without the else.

2005-02-25 Thread Chris W. Parker
Jochem Maas mailto:[EMAIL PROTECTED]
on Friday, February 25, 2005 4:04 PM said:

 just do:
 
 if ($something) $this = $that;

 Thanks!
 Chris.
 
 p.s. No need to respond if your suggestion is:
 
 ?php
 
   if($something) { $this = $that; }

 ?

:)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Like ternary but without the else.

2005-02-25 Thread Chris W. Parker
Justin Lilly mailto:[EMAIL PROTECTED]
on Friday, February 25, 2005 3:10 PM said:

 This should do the trick:
 
 $something ? $this=$that

Actually that gives a synax error. But I've figured it out based on your
suggestion.

It's actually:

?php

  $something  $this = $that;

?



Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Like ternary but without the else.

2005-02-25 Thread Guillermo Rauch
On Fri, 25 Feb 2005 18:39:56 -0500, Brian V Bonini [EMAIL PROTECTED] wrote:
 On Fri, 2005-02-25 at 13:36, Chris W. Parker wrote:
  How can I turn the following into something that resembles the ternary
  operator?
 
  ?php
 
if($something)
{
  $this = $that;
}
 
  ?
 
 $this = (isset($something)) ? $something : $that;
 
 The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1
 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.
 
 --
 
 s/:-[(/]/:-)/g
 
 BrianGnuPG - KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
 ==
 gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
 Key Info: http://gfx-design.com/keys
 Linux Registered User #339825 at http://counter.li.org
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

What the user actually requested is the following method, fairly used
in bash scripting.

($a == $b)  $a = 'asdasd';

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php