I am trying to use PHP to build HTML that I will later display. I have the following lines:
$currentName = "test";
$numberToGiveDropDownHTML = "<Select name='$currentName[]'>\n";
But I get the following error:
Parse error: syntax error, unexpected
‘]’, expecting T_STRING or T_VARIABLE
or T_NUM_STRING in…
What is wrong with that? I thought I could that and later use the $_POST super global.
Thanks!
PHP will try to parse variables in a double string automatically. Consider the following:
PHP will convert $a to foo for you, given it’s in double quotes. In your scenario, it’s thinking (the parser that is) that the
[]is part of the in-line variable.You can do one of two things: use
{$currentname}so the parser doesn’t keep going, or break the string out and concatenate the variable in, e.g....".$currentname."[]...