Bug #15378 Updated: 3d array variables not usable in double quotes
| From: | torben@php.net | Date: | Tue, 05 Feb 2002 19:27:16 +0000 |
| Subject: | Bug #15378 Updated: 3d array variables not usable in double quotes | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-79265@lists.php.net to get a copy of this message | ||
ID: 15378
Updated by: torben@php.net
Reported By: php.net@chiefworks.com
Status: Bogus
Bug Type: Arrays related
Operating System: Linux 2.4, Apache 1.3.22
PHP Version: 4.1.1
New Comment:
> edink@php.net -- I was aware of that syntax but there are
> some cases (sql querys, cookies & headers) where it is not
> possible to write it that way and the only solution WAS to
> assign it to a simpler variable.
Not true--that syntax is possible anywhere you use strings, except for
heredocs.
Torben
Previous Comments:
------------------------------------------------------------------------
[2002-02-05 11:48:43] php.net@chiefworks.com
edink@php.net -- I was aware of that syntax but there are some cases
(sql querys, cookies & headers) where it is not possible to write it
that way and the only solution WAS to assign it to a simpler variable.
mfischer@php.net -- Thanks. I guess that solves this problem. And this
is documented where?
------------------------------------------------------------------------
[2002-02-05 06:29:42] mfischer@php.net
This is not true. The following is perfectly valid:
echo "My first name is {$var['name']['first']}!";
------------------------------------------------------------------------
[2002-02-05 03:21:08] edink@php.net
The correct syntax is:
echo "My first name is ".$var[name][first]."!";
You cannot have comples variables inside quotes.
------------------------------------------------------------------------
[2002-02-05 00:34:07] php.net@chiefworks.com
I should add that the the first level of the array works fine, it is
just the second (& following) levels that cannot be used.
<?php
// This works:
$var[name] = 'Caleb';
echo "I am $var[name]";
// This does not:
$var[name][first] = 'caleb';
echo "I am $var[name][first]";
------------------------------------------------------------------------
[2002-02-05 00:30:39] php.net@chiefworks.com
<?php
$var = array(
'name' => array(
'first' => 'Caleb',
'last' => 'Maclennan'
)
);
echo "My first name is $var[name][first]!";
?>
Acutal Result:
My first name is Array[first]!
Correct Result:
My first name is Caleb!
This get's really nasty when useing 3 dimentional arrays to put data in
SQL querys. The above example can easily be done by takeing the
variable out of the quotes and useing "." to add it to the end, but
there are other cases where the only solution is to do like this:
<?php
$tempVar = $var[name][first];
echo "My name is $tempVar";
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=15378&edit=1