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
zylinder
Forum Newbie
Posts: 9 Joined: Thu Feb 17, 2005 1:27 pm
Location: Austria
Post
by zylinder » Thu Feb 17, 2005 1:59 pm
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.
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Thu Feb 17, 2005 2:07 pm
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 » Thu Feb 17, 2005 2:19 pm
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 » Thu Feb 17, 2005 2:21 pm
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
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Feb 17, 2005 2:22 pm
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 » Thu Feb 17, 2005 2:23 pm
It works!
Thank you!
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Feb 17, 2005 2:29 pm
Code: Select all
$help_lvA = (isset($_POSTї'help_lvA']) ? $_POSTї'help_lvA'] : 'somedefaultvalue');