Forum Moderators: coopster

Message Too Old, No Replies

trouble with arrays

help me sort these out please

         

proper_bo

6:03 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



I have these two array:
array(5) {
["bus_id"]=>
string(3) "117"
["map_id"]=>
string(2) "54"
["description"]=>
string(13) "children code"
["text"]=>
string(27) "children must be out by 8pm"
["image"]=>
string(0) ""
}

array(5) {
["bus_id"]=>
string(3) "117"
["map_id"]=>
string(2) "33"
["description"]=>
string(5) "hours"
["text"]=>
string(13) "this is hours"
["image"]=>
string(0) ""
}

and I would like to turn them into this:
array(
. .'54'=>array(
. . .["bus_id"]=>
. . ."117"
. . .["map_id"]=>
. . ."54"
. . .["description"]=>
. . ."children code"
. . .["text"]=>
. . ."children must be out by 8pm"
. . .["image"]=>
. . .""
. . .),
. .'33'=>array(
. . .["bus_id"]=>
. . ."117"
. . .["map_id"]=>
. . ."33"
. . .["description"]=>
. . ."hours"
. . .["text"]=>
. . ."this is hours"
. . .["image"]=>
. . .""
. . .)
);

clear as mud? thank you.

proper_bo

7:05 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



to answer this:

to keep keys entact just use

$array_final = $array1 + $array2;

directrix

9:51 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



Well, I'm glad you're happy, but that doesn't seem to answer your original question!

If I'm reading it correctly, you wanted to take the two arrays and make them two elements of a new array, keyed on map_id of the old arrays. Something like the following would do that:

$array_final = array($array1['map_id'] => $array1, $array2['map_id'] => $array2);