[nycphp-talk] need help understanding parsing difference
Adam Maccabee Trachtenberg
adam at trachtenberg.com
Tue Nov 4 14:17:07 EST 2003
On Tue, 4 Nov 2003, Michael Southwell wrote:
> When $PRODUCTS[$here]["v1b"]="holster"
> and $j="v1b"
> echo "<a href=\"path/$PRODUCTS[$here][$j]\"... evaluates to path/Array[v1b]
> which is meaningless
> but echo "<a href=\"path/".$PRODUCTS[$here][$j]."\"... evaluates to
> path/holster which is correct (or to be more precise, what I wanted).
PHP doesn't know if you're referring to a two dimentional array named
$PRODUCTS or some other potential weirdly constructed variable. They
way to solve this while still using double quotes is to place the
whole variable inside of {}s:
echo "{$PRODUCTS[$here][$j]}"
This "forced coersion" feature isn't well known.
-adam
--
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!
More information about the talk
mailing list