Welcome Guest, Not a member yet? Register   Sign In
syntax question

what is the difference between

$variable .= form_input('name', '');


$variable = form_input('name', '');

why is there a . in front an equal sign?

= will assign to a var(which will overwrite the old value).
.= will append to a var(concatenating).

Just to add (or concatenate) to what rogierb said, you need to make sure you initialise the variable before concatenation to it, so in most cases, you set it to an empty string and then do all the concatenation

Thank you very much?
One more question, let's say I want to use .= to append something,
how could I append it, but start from a new line?

That depends if you're talking about a new line as it would appear in a file or a line break on a website
If it's the first, you just put either \n or \r\n as part of the concatenated string for UNIX and windows respectively, you need to do this in double quotes so that it gets interpreted correctly.
If it's the latter, just add <b r /> (remove space between b and r) as part of the string, this can be as part of a string in single or double quotes

I am actually working on a form.
I want to use .= for two input fields, but I don't want them to be next to each other when they're displayed in the browser. I want to have one input field displays on only one line.

[quote author="babyboss" date="1245250899"]what is the difference between
$variable .= form_input('name', '');

Since we're all having a go .. the operator-in-front-of-the-equals-sign works with many of the arithmetic operators too (+ / - are more often used).

These two code bites do the same thing:
$variable = "bob";
$variable .= form_input('name', '');

$variable = "bob";
$variable = $variable  .  form_input('name', '');

I'm pretty sure they talk about this in the [url="http://www.php.net/manual/en/language.operators.string.php"]PHP manual[/url] somewhere ...

Wow. A flurry of fast activity.

If you don't want to display two fields next to each other, this isn't a string concat question, so much as an HTML layout one.

Is there a particular reason why you need to concatenate strings to make a form?
You should render the form in a view file, where you can use plain HTML (outside of PHP tags) or echo each part directly from within the PHP tags

Now back to the actual question at hand, there are several ways to do this
The easiest method, and the way I do it (as all my forms are styled the same) is to use CSS, or more specifically the display element. By setting this to 'block', input fields will display under each other, instead of next to each other, even if you don't put anything else in the HTML to do this
// The CSS
input {
  display: block;
  ... any other rules here

The other option is to just put a <b r /> (remove space between b and r) in between the 2 fields

Theme © iAndrew 2016 - Forum software by © MyBB