[PHP] arrays and same index

2002-05-30 Thread Victor Spång Arthursson

Hi!

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?

Sincerely

Victor


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] arrays and same index

2002-05-30 Thread Cal Evans

$array[untitled_1.jpg] = array(0,3,4,0,1)

Or you could :
$array[untitled_1.jpg] = array();

$array[untitled_1.jpg][0]=0
$array[untitled_1.jpg][1]=3
$array[untitled_1.jpg][2]=4
$array[untitled_1.jpg][3]=0
$array[untitled_1.jpg][4]=1


Then you can access them by using:
echo $array[untitled_1.jpg][0] // = 0;
echo $array[untitled_1.jpg][1] // = 3;
echo $array[untitled_1.jpg][2] // = 4;
echo $array[untitled_1.jpg][3] // = 0;
echo $array[untitled_1.jpg][4] // = 1;

or:
$x = $array[untitled_1.jpg];
echo $x[0];
echo $x[1];
echo $x[2];
echo $x[3];
echo $x[4];

HTH,
=C=
*
* Cal Evans
* Journeyman Programmer
* Techno-Mage
* http://www.calevans.com
*
 

-Original Message-
From: Victor Spang Arthursson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 30, 2002 8:37 AM
To: [EMAIL PROTECTED]
Subject: [PHP] arrays and same index


Hi!

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?

Sincerely

Victor


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] arrays and same index

2002-05-30 Thread Stuart Dallas

Victor Spång Arthursson [EMAIL PROTECTED] 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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] arrays and same index

2002-05-30 Thread Ed Gorski

Well what exactly are you trying to do?  You can't name an index of an 
array the same thing and expect different values

ed

At 03:36 PM 5/30/2002 +0200, Victor Spång Arthursson wrote:
Hi!

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?

Sincerely

Victor


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php