this cause error:
$xml .= "\t<team id=\"$team['id']\"";
this doesn't cause error:
$xml .= "\t<team id=\"\"";
What's the problem?
Salman Arshad
273k85 gold badges450 silver badges540 bronze badges
asked Dec 24, 2012 at 10:48
MTVS
2,0965 gold badges27 silver badges38 bronze badges
5 Answers 5
You can either remove the single quotes:
$xml .= "\t<team id=\"$team[id]\"";
Or you can use the curly brackets inside double quoted strings using one of the following syntax:
$xml .= "\t<team id=\"{$team['id']}\"";
$xml .= "\t<team id=\"${team['id']}\"";
Reference (scroll down to the "variable parsing" section).
Few more examples:
echo "$team[id]";
echo "{$team['first name']}"; // e.g. when there are spaces in key names
echo "{${getVarName()}}"; // e.g. when we cannot use $ directly
answered Dec 24, 2012 at 10:53
Salman Arshad
273k85 gold badges450 silver badges540 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
This should work:
$xml .= "\t<team id=\"$team[id]\"";
See how I removed the single quotes around the id.
answered Dec 24, 2012 at 10:53
Kenny
5,4007 gold badges32 silver badges45 bronze badges
Comments
Try this:
$xml .= "\t<team id='".$team['id']."'";
answered Dec 24, 2012 at 10:54
Chetana Kestikar
5706 silver badges23 bronze badges
Comments
Try This
$xml .= "\t<team id=\"".$team['id']."\"";
Or you can use the curly brackets like this
$xml .= "\t<team id=\"{$team['id']}\"";
answered Dec 24, 2012 at 10:52
Toretto
4,7115 gold badges29 silver badges46 bronze badges
Comments
I think the problem is the $team['id'] more than the double quotes.
Have you tried:
$xml .= "\t<team id=\"".$team['id']."\"";
answered Dec 24, 2012 at 10:53
Naryl
1,8881 gold badge10 silver badges12 bronze badges
2 Comments
Naryl
totally true, changing to double quotes again.
lang-php