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 #169973 is a reply to message #169966] Sat, 02 October 2010 13:39 Go to previous messageGo to previous message
August Karlstrom is currently offline  August Karlstrom
Messages: 16
Registered: October 2010
Karma:
Junior Member
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: Wed Nov 27 12:20:29 GMT 2024

Total time taken to generate the page: 0.03259 seconds