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 #169998 is a reply to message #169985] Mon, 04 October 2010 09:50 Go to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma:
Senior Member
On 3 Oct, 03:04, Martin <warwo...@gmail.com> wrote:
> 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

Please do not top post (top posting fixed)
> 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.

It is a lot easier for us to help you with problems in your code if
you post the code that has problems rather than other arbitrary code
that you have made up on teh spot.
[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 07:03:19 GMT 2024

Total time taken to generate the page: 0.04644 seconds