FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Dot in array key name
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Dot in array key name [message #169985 is a reply to message #169973] Sun, 03 October 2010 02:04 Go to previous messageGo to previous message
Martin is currently offline  Martin
Messages: 8
Registered: October 2010
Karma:
Junior Member
Thanks for the replies.

The code i posted was typed from memory and being a javascript bod i
didn't get the syntax correct, but in the code i'm debugging i did use
isset() and the array wasn't being reset within the loop.

I had previously done a simple test which produced no errors:

<?php

$i=array();

$i['myName']='this is ok';

$i['afile.nam']='is this ok?';

print_r($i);

?>

So was hoping that the dot was ok which is now confirmed.

I shall look elsewhere for the bug....

Martin.


August Karlstrom wrote:
> On 2010-10-02 08:30, Martin wrote:
>> $icons=array();
>>
>> $icon_name='myicon.png';
>>
>> if($icons[$icon_name]){
>> // the image has already been loaded
>> $icon=$icons[$icon_name];
>> } else {
>> $icon=imagecreatefrompng($icon_name);
>> $icons[$icon_name]=$icon;
>> }
>
> In the code above you reset the icon array each time the script is run,
> which is probably not what you want. You should also use the function
> isset in the if-statement condition so it can handle all file names
> correctly including "0" and "0.0" (both interpreted as boolean false):
>
> if (!isset($icons[$icon_name])) {
> $icons[$icon_name] = imagecreatefrompng($icon_name);
> }
> $icon = $icons[$icon_name];
>
>> I'm trying not to load an image more than once if it is required more
>> than once.
>>
>> Anyway - i have a bug where sometimes the wrong image is used and
>> wondered whether the dot in the image's filename is invalid syntax for
>> an array key name?
>
> No, it's perfectly valid.
>
>
> /August
>
> --
> The competent programmer is fully aware of the limited size of his own
> skull. He therefore approaches his task with full humility, and avoids
> clever tricks like the plague. --Edsger Dijkstra
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Inserting into associative array
Next Topic: php ide with checkpoint restart is there?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 06:52:24 GMT 2024

Total time taken to generate the page: 0.03701 seconds