Jump to content
ckrudelux

Set Multible Variables On One Line.

Recommended Posts

I don't get any errors and for me this would be a good way to do this, but is this bad practice and should this be avoided?

 if(!isset($var1) && !isset($var2))	($var1 = 1).($var2 = 2); echo $var1."\n";echo $var2; 

Edited by ckrudelux

Share this post


Link to post
Share on other sites

The concatenation operator doesn't do anything in that case. I guess you can use a construct like that if you want to avoid using curly brackets to enclose the two statements, but you're not saving the result of the concatenation so it's not really doing anything other than setting the two variables.

Share this post


Link to post
Share on other sites
The concatenation operator doesn't do anything in that case. I guess you can use a construct like that if you want to avoid using curly brackets to enclose the two statements, but you're not saving the result of the concatenation so it's not really doing anything other than setting the two variables.
I was not intressed in saving but only setting the variables, removing the concatenation operator would result in an error. I just saw that it's just as big job at using curly brackets as using parentheses, easy thing to overlook I guess. Edit: What I was looking for was something simular to this:
$var1 = 1, $var2 = 2;

Edited by ckrudelux

Share this post


Link to post
Share on other sites

Why do you want to condense the code like that?

Share this post


Link to post
Share on other sites

Assignment is just a normal statement that returns the value that was assigned — there is no requirement that it goes on a line by itself. This is why things like

for ($row = mysql_fetch_assoc($query)) ...

work. You could do anything:

$a = "a" . ($a = 5) + ($a = 10) ? $a = 10 / $a = 5 : $a = "thing";

Maybe you are thinking about list()?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...