Re: arrays and same index
| From: | Stuart Dallas | Date: | Thu, 30 May 2002 13:54:57 +0000 |
| Subject: | Re: arrays and same index | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-99911@lists.php.net to get a copy of this message | ||
Victor Spång Arthursson <scooterbabe@mac.com> wrote:
> I want to create an array that looks like follows:
>
> $array["untitled_1.jpg"][] = 0
> $array["untitled_1.jpg"][] = 3
> $array["untitled_1.jpg"][] = 4
> $array["untitled_2.jpg"][] = 0
> $array["untitled_3.jpg"][] = 1
>
> What I'm thinking about is accessing all "untitled_1.jpg" values by
> doing the following:
>
> $newarray = $array["untitled_1.jpg"];
>
> and receive an array with 3 indexes which has the values 0,3,4...
>
> This doesn't works...
>
> $array["untitled_1.jpg"][] = 3 seems to overwrite
> $array["untitled_1.jpg"][] = 0 and then $array["untitled_1.jpg"][] = 4
> overwrites $array["untitled_1.jpg"][] = 3...
>
> How should I solve this?
It seems to work for me. The file...
<pre><?php
$array["untitled_1.jpg"][] = 0;
$array["untitled_1.jpg"][] = 3;
$array["untitled_1.jpg"][] = 4;
$array["untitled_2.jpg"][] = 0;
$array["untitled_3.jpg"][] = 1;
print_r($array["untitled_1.jpg"]);
$array["untitled_1.jpg"][] = 3;
$array["untitled_1.jpg"][] = 0;
$array["untitled_1.jpg"][] = 4;
print_r($array);
?></pre>
The result: http://www.devserver.org/arraytest.php
--
Stuart