Page 1 of 1

need help to shorten a little code snippet

Posted: Thu Feb 17, 2005 1:59 pm
by zylinder
Is there a way to make the code shorter so it fits 1 line

Code: Select all

if(isset($_POSTї'$foo']))
   $x = $_POSTї'$foo'];
My first thought does not work:

Code: Select all

if(isset($_POSTї'$foo'])) = $x
!! This is my first post here. I hope its no stupid question.

Posted: Thu Feb 17, 2005 2:07 pm
by shiznatix
yep

Code: Select all

(isset($_POSTї'$foo']) ? "$x=$_POSTї'foo']" : "");

Posted: Thu Feb 17, 2005 2:19 pm
by zylinder
Didnot work. Code produces the following error:


Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Posted: Thu Feb 17, 2005 2:21 pm
by zylinder
I think it was my error the org code looks like this.

Code: Select all

if(isset($_POSTї'help_lvA']))
	$help_lvA = $_POSTї'help_lvA'];
A string and not $foo

Posted: Thu Feb 17, 2005 2:22 pm
by s.dot

Code: Select all

if(isset($_POSTї'help_lvA'])) { $help_lvA = $_POSTї'help_lvA']; }

Posted: Thu Feb 17, 2005 2:23 pm
by zylinder
It works!

Thank you!

Posted: Thu Feb 17, 2005 2:29 pm
by John Cartwright

Code: Select all

$help_lvA = (isset($_POSTї'help_lvA']) ? $_POSTї'help_lvA'] : 'somedefaultvalue');