Bug #15378 Updated: 3d array variables not usable in double quotes
| From: | edink@php.net | Date: | Tue, 05 Feb 2002 08:21:09 +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-79186@lists.php.net to get a copy of this message | ||
ID: 15378
Updated by: edink@php.net
Reported By: php.net@chiefworks.com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Linux 2.4, Apache 1.3.22
PHP Version: 4.1.1
New Comment:
The correct syntax is:
echo "My first name is ".$var[name][first]."!";
You cannot have comples variables inside quotes.
Previous Comments:
------------------------------------------------------------------------
[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