Scooby08 Posted December 3, 2009 Share Posted December 3, 2009 Here's how the array's are created.. <?php while ($x = readdir($dp)) { $order[] = $p['order']; $files[] = $x; } ?> Here's a sample of how they come out.. Array ( [0] => c [1] => f [2] => a [3] => b [4] => d [5] => b [6] => [7] => e ) Array ( [0] => learn-more [1] => apple.php [2] => company-info [3] => zigzag.php [4] => products-services [5] => customer-support [6] => index.php [7] => service-agreements ) How could I sort the files array by using the values of the order array and also make index.php always first to get something like so: Array ( [0] => index.php [1] => company-info [2] => zigzag.php [3] => customer-support [4] => learn-more [5] => products-services [6] => service-agreements [7] => apple.php ) Link to comment https://forums.phpfreaks.com/topic/183803-need-some-ideas-as-to-how-to-go-about-sorting-this-array/ Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2009 Share Posted December 3, 2009 any reason for two arrays ? , you could make the porder the key of the $files array and sort it on that ? Link to comment https://forums.phpfreaks.com/topic/183803-need-some-ideas-as-to-how-to-go-about-sorting-this-array/#findComment-970206 Share on other sites More sharing options...
Scooby08 Posted December 3, 2009 Author Share Posted December 3, 2009 I tried that way, but if two, three or four keys are the same for example, all gets deleted but one.. That's why I had two b's in the order.. I need to be able to have duplicates.. Link to comment https://forums.phpfreaks.com/topic/183803-need-some-ideas-as-to-how-to-go-about-sorting-this-array/#findComment-970213 Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2009 Share Posted December 3, 2009 had to edit since I found the function I was looking for <?php $order = array('c','f','a','b','d','b','','e'); $files = array('learn-more','apple.php','company-info','zigzag.php','products-services','customer-support','index.php','service-agreements'); array_multisort($order, $files); print_r($files); ?> Link to comment https://forums.phpfreaks.com/topic/183803-need-some-ideas-as-to-how-to-go-about-sorting-this-array/#findComment-970217 Share on other sites More sharing options...
Scooby08 Posted December 3, 2009 Author Share Posted December 3, 2009 Ahh nice! Thanks rajivgonsalves!! I think that'll work just lovely! Link to comment https://forums.phpfreaks.com/topic/183803-need-some-ideas-as-to-how-to-go-about-sorting-this-array/#findComment-970221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.