Re: [SMARTY] Associative array access with space in key
| From: | Greg Dykema | Date: | Fri, 19 Apr 2002 19:52:26 +0000 |
| Subject: | Re: [SMARTY] Associative array access with space in key | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3821@lists.php.net to get a copy of this message | ||
On Fri, 19 Apr 2002 08:24:04 -0500, Andrei Zmievski wrote:
>On Thu, 18 Apr 2002, Greg Dykema wrote:
>>Greetings,
>>
>>I've been through the manual and the mailing list archives, but I can't
>>figure out how to make a reference to an associative array element whose
>>key contains a space. For example, I've got an array with elements like
>>
>>$a["Class ID"] = 1234;
>>
>>I've tried { $a.Class ID } and { $a."Class ID" } but just get errors.
>>References without spaces in the key work fine. Unfortunately the data
>>structure is coming from a database access routine and I have no way of
>>knowing what characters might be used in the keys.
>
>Currently, you cannot use access keys with spaces in them. In the next
>release of Smarty you can do this workaround:
>
>{assign var="mykey" value="Class ID"}
>{$a.$mykey}
When is the next release expected?
>>Actually, the actual data structure is a combination of associative
>>arrays and arrays, so the real references I'm making look like
>>{ $a.foo[0] }.
>
>I don't see anything wrong with {$a.foo[0]}.
That works fine, I just mentioned it in case a different solution was
required in that case.
BTW, what other characters won't work in the key? I know I will encounter
keys with at least the following:
# % / \
>
>-Andrei
>
>"The most exciting phrase to hear in science, the one that heralds new
>discoveries, is not "Eureka!" but "That's funny..." -- Isaac Asimov.
>