At 12:42 17-6-03, you wrote:
the first will generate a warning if warnings are enabled.
it could mean a constant or a string, if a constant with that name is not available
php will use it as a string and show a warning.
the second is right as a string.
in addition to that.

In your example the array key is a string.
'foo' is a string.
(if $string_a='foo'; ) $string_a is a string
foo is not a string
but after define('foo','stringvalue');, foo is a CONSTANT with a string value. see http://www.php.net/define


If you type $_POST[foo] in a piece of code, PHP recognizes that foo is not a normal string such as 'foo', and not a variable as it does not have a $. So then PHP checks its definition-list to see if 'foo' is defined. If not, PHP will issue a warning (if turned on) that says something like "i assume you mean 'foo'") and uses the string 'foo' as key. This is extra work for PHP and should be avoided, although you see it a lot.

There is one confusing exception: within double quotes strings, you may use array keys without the quotes. "For example like $_POST[foo]";. If you can, I recommend using 'For example like '.$_POST['foo'].

Last one: $_POST["foo"] is ok too but now PHP will first check the string "foo" for possible variables inside: (a little bit of ) extra work that is not there with single quotes ($_POST['foo']).





Thomas

On Tue, 17 Jun 2003 11:09:14 +0300 [EMAIL PROTECTED] (Jarmo Järvenpää) wrote:

> Hi
>
> A quickie, how does the $_POST[foo] and $_POST['foo'] differ?
> Both do work.
>
>
> BR,
> Jarmo



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to