Re: Building Dynamic Value list using ohp
| From: | Evan Nemerson | Date: | Thu, 27 Sep 2001 03:06:28 +0000 |
| Subject: | Re: Building Dynamic Value list using ohp | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-68939@lists.php.net to get a copy of this message | ||
On another side-note, I haven't had trouble with echo "foo $arr[$a]" which is
very handy in loops (especially for, while, and foreach)
Also, nice to have you back, Maxim
On Wednesday 26 September 2001 09:28 am, you wrote:
> > The reason for it is that within double quote you can parse for 'simple'
> > variables only (es: $var, not $var[]). Otherwise it gives you a parse
> > error.
>
> Just a quick note, this is partially true. The following works :
>
> error_reporting(E_ALL);
>
> $arr = array ('a' => 'apple','b' => 'banana');
>
> print "I'd like an $arr[a] today, and a {$arr['b']} too";
>
> I used to assume "foo $arr[a]" would give a Warning but it doesn't as the
> constant 'a' isn't looked for in the string, but :
>
> print $arr[a]; // apple and a Warning
> // Warning: Use of undefined constant a - assumed 'a'
>
> define('a','b'); // define a as a constant with value of b
>
> print $arr[a]; // banana and no Warning
> print $arr['a']; // apple and no Warning (quotes are good)
>
> Numerical arrays work fine in a string, such as "foo $array[0]".
>
> Maxim is referring to "foo $arr['a']" creating a parse error, one that
> looks like :
>
> Parse error: parse error, expecting
T_STRING' or
> T_VARIABLE' or
> `T_NUM_STRING' in /www/htdocs/test.php on line 4
>
> As it does. The Warnings shown above refer to the E_NOTICE level. Have
> fun and yes, this is a digression and off-topic :)
>
> Regards,
> Philip Olson
>
> > 1. this:
> > print("<option value=\"$row[0]\">$row[0]</option>");
> > should be this:
> > print("<option value=\"{$row[0]}\">{$row[0]}</option>");
> > or like this:
> > echo '<option
> > value="'.$row[0].'">'.$row[0].'</option>');
> >
> > The reason for it is that within double quote you can parse for 'simple'
> > variables only (es: $var, not $var[]). Otherwise it gives you a parse
> > error.