naeembhatti Posted December 20, 2006 Share Posted December 20, 2006 hi guys how are u i am in trouble plz help me, my prob is.i have 3 arraysA = 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 orderarray(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]=>1i 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 https://forums.phpfreaks.com/topic/31325-how-to-sort-multi-array-to-make-a-single-array/ Share on other sites More sharing options...
artacus Posted December 20, 2006 Share Posted December 20, 2006 [code]asort($a);foreach ($a as $key=>$val) { $disp .= "<a href='$c[$key]'><img src='$b[$key]' /></a>";}[/code] Link to comment https://forums.phpfreaks.com/topic/31325-how-to-sort-multi-array-to-make-a-single-array/#findComment-144959 Share on other sites More sharing options...
naeembhatti Posted December 20, 2006 Author Share Posted December 20, 2006 thax very much artacus.it is looking easy now but it was looking very difficult to me. Link to comment https://forums.phpfreaks.com/topic/31325-how-to-sort-multi-array-to-make-a-single-array/#findComment-144970 Share on other sites More sharing options...
naeembhatti Posted December 20, 2006 Author Share Posted December 20, 2006 will u plz explain me a very brief description of ur solutionthanx artacus. Link to comment https://forums.phpfreaks.com/topic/31325-how-to-sort-multi-array-to-make-a-single-array/#findComment-144974 Share on other sites More sharing options...
artacus Posted December 20, 2006 Share Posted December 20, 2006 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 https://forums.phpfreaks.com/topic/31325-how-to-sort-multi-array-to-make-a-single-array/#findComment-144978 Share on other sites More sharing options...
naeembhatti Posted December 20, 2006 Author Share Posted December 20, 2006 wawooo thank u very much it works very fine but i was not 100% sure that what is happening lol.now i got it thanks u once agin. Link to comment https://forums.phpfreaks.com/topic/31325-how-to-sort-multi-array-to-make-a-single-array/#findComment-144980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.