need help to shorten a little code snippet

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

Post Reply
zylinder
Forum Newbie
Posts: 9
Joined: Thu Feb 17, 2005 1:27 pm
Location: Austria

need help to shorten a little code snippet

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

yep

Code: Select all

(isset($_POSTї'$foo']) ? "$x=$_POSTї'foo']" : "");
zylinder
Forum Newbie
Posts: 9
Joined: Thu Feb 17, 2005 1:27 pm
Location: Austria

Post 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
zylinder
Forum Newbie
Posts: 9
Joined: Thu Feb 17, 2005 1:27 pm
Location: Austria

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

if(isset($_POSTї'help_lvA'])) { $help_lvA = $_POSTї'help_lvA']; }
zylinder
Forum Newbie
Posts: 9
Joined: Thu Feb 17, 2005 1:27 pm
Location: Austria

Post by zylinder »

It works!

Thank you!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

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