Page 1 of 1

buidling a mutli dimentional array

Posted: Sun Dec 26, 2004 8:30 am
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

Posted: Sun Dec 26, 2004 8:34 am
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. :?

what i mean this :L

Posted: Sun Dec 26, 2004 8:54 am
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

Posted: Sun Dec 26, 2004 9:01 am
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);

ok but can i do :

Posted: Sun Dec 26, 2004 9:12 am
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