Jump to content

how to sort multi array to make a single array?


naeembhatti

Recommended Posts

hi guys how are u i am in trouble plz help me, my prob is.

i have 3 arrays

A = Array ( [0] => 2 [1] => 1 [2] => 3 [3] => 4 [4] => 5 [5] => 7 [6] => 6 )
B=  Array ( [0] => http://localhost/script/images/children/img1.jpg [1] => http://localhost/script/images/children/img3.jpg [2] => http://localhost/script/images/children/img2.jpg [3] => http://localhost/script/images/children/img4.jpg [4] => http://localhost/script/images/children/img10.jpg [5] => http://localhost/script/images/children/img10.jpg [6] => http://localhost/script/images/children/img10.jpg )
C=  Array ( [0] => http://localhost/script/01 [1] => http://localhost/script/03 [2] => http://localhost/script/! [3] => http://localhost/script/04 [4] => http://localhost/script/10 [5] => http://localhost/script/a [6] => http://localhost/script/description )
======================
array(A)-> defines the sort order
array(B)-> should be as sort order of array(A)
array(C)-> should be as sort order of array(A)

actually array(A) is a main array which contains the sort order like in [0]=>2 , [1]=>1
i want so make a single array having sort order of array(A)

like if array(A) have its 1st element to 2 then i want to pick 2nd element from array(B) and from array(C)
i want to make a double dimension array
Link to comment
Share on other sites

Ok, asort($a) sorts $a and keeps the index association. (If you used regular sort($a) you wouldn't see any difference because while it would sort your array, it would also reindex it.)

The foreach($a as $key=>$val) just iterates thru every element of your $a array. (We can't use for($i=0; $i<count;$i++) because you'd lose your sort order.) As it goes thru each one, it assigns the key to the $key variable and value to the $val variable. In this case we really don't care about the $val, we really want to get $key because that will tell us which elements of $b and $c to pull next.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.