View Full Version : String Interpolation
marain
05-13-2012, 12:27 PM
This works:
echo $quotations [4];
echo "<br />";
echo $quotations [5];
echo "<br />";
echo "The PHP End";
This doesn't:
echo "$quotations [4] <br /><br /> $quotations [5] <br /><br />";
Am I misunderstanding string interpolation?
A.
echo "$quotations [4] <br /><br /> $quotations [5] <br /><br />";PHP doesn't realize that the indices are part of the variables - it thinks they're part of the string.
You can resolve the ambiguity by using brackets:
echo "{$quotations[4]}<br>{$quotations[5]}<br>";
(Incidentally, see how you can tell what's wrong by looking at the colors in the code highlighting? When you code, use an editor that does that. very helpful.)
ApacheTech
05-13-2012, 06:56 PM
(Incidentally, see how you can tell what's wrong by looking at the colors in the code highlighting? When you code, use an editor that does that. very helpful.)
http://notepad-plus-plus.org/
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.