buidling a mutli dimentional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

buidling a mutli dimentional array

Post by pelegk2 »

i want to build an array thats its data is :
name,id,tonn

the only 1 of the 3 values that can repeat on itself is the "tonn"
i can have data like :
name id tonn
sd 3 2
cd 1 2
we 443 55
qa 2311 2
and i want the array build based on the tonn as the main index of the array!!!
how can i do this?
1 more thing : i dont know i advance the "tonn" ' i only get it at run time
ordered by tonn - so the array keys (based on the tonn???) must be build at run timme!
thnaks in advance
peleg
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your example has tonn as a one to many relationship to the other data in the result set. that's a very inefficient main index, as php will only allow unique indices in arrays. I'm confused as to what you are trying to accomplish. :?
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

what i mean this :L

Post by pelegk2 »

for example i want an array:

Code: Select all

sd 3 2 
cd 1 2 
we 443 55 
qa 2311 2

will be : 
array={2=>{{"sd",3},{"cd",1},{"qa",2311}},55=>{{"we",443}}}
is this possible?
thnaks i nadvance
peleg
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

technically, it's possible, but can be a general organizational nightmare.. at least it has been for me. :)

Code: Select all

$example = array();

$exampleї2]ї] = array('sd', 3);
$exampleї2]ї] = array('cd', 1);
$exampleї55]ї] = array('we', 443);
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

ok but can i do :

Post by pelegk2 »

$example["2"][]
instead of :
$example[2][]

bacuse in the end i wan to use this arrays in javascript!
so in that case i preffer to use $example["2"] and not $example[2]
beacuse if i have 2 and 55 i have between them 53 empty cells!!!!
so what do you say about it?
thnaks i nadvane
peleg
Post Reply