jcvincent Posted August 22, 2012 Share Posted August 22, 2012 Good day all, I have two arrays; 1. An array that holds the correct sorting of the jobs to be executed, 2. An array that holds the current trigger files that were created to run specific jobs. In the 2nd array, the sorting is alphabetical based on how GLOB() read the directory where the trigger files are saved. I want to correct the sorting of array number 2 based on the sorting in Array 1. Array number 1's values are based on a text file I created with the proper sorting (based on the priority list in a batch file). Below is what the text file looks like: ActSMvar.txt ActMMvar.txt StatSMvar.txt StatMMvar.txt EA_Asia_Automation_Ready.txt EA_Corp_Automation_Ready.txt Agg_QRF_Ready.txt HYP_Stats_SCM_Ready.txt HYP_Stats_Care_Ready.txt HP_Subs_Ready.txt EA_Currency_Rates_Ready.txt CorpRpts_DIM_Export_Ready.txt Global_Headcount_Ready.txt Asia_Actuals_HP_Ready.txt As you can see, array number 1 will look like this: Array ( [ 0 ] => ActSMvar.txt [1] => ActMMvar.txt [2] => StatSMvar.txt [3] => StatMMvar.txt [4] => EA_Asia_Automation_Ready.txt [5] => EA_Corp_Automation_Ready.txt [6] => Agg_QRF_Ready.txt [7] => HYP_Stats_SCM_Ready.txt [8] => HYP_Stats_Care_Ready.txt [9] => HP_Subs_Ready.txt [10] => EA_Currency_Rates_Ready.txt [11] => CorpRpts_DIM_Export_Ready.txt [12] => Global_Headcount_Ready.txt [13] => Asia_Actuals_HP_Ready.txt ) Currently, array number 2 looks like this: Array ( [ 0 ] => ActMMvar.txt [1] => ActSMvar.txt [2] => Agg_QRF_Ready.txt [3] => EA_Asia_Automation_Ready.txt [4] => EA_Corp_Automation_Ready.txt [5] => StatMMvar.txt [6] => StatSMvar.txt ) Now, I want to know how will I force the sorting of array number 1 to array number 2? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/267408-array-sorting-based-on-another-array/ Share on other sites More sharing options...
Barand Posted August 22, 2012 Share Posted August 22, 2012 try $sorted = array_intersect ($array1, $array2); echo '<pre>'.print_r($sorted, 1).'</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/267408-array-sorting-based-on-another-array/#findComment-1371352 Share on other sites More sharing options...
jcvincent Posted August 23, 2012 Author Share Posted August 23, 2012 Thank you very much Barand. ARRAY_INTERSECT is just what I need. Quote Link to comment https://forums.phpfreaks.com/topic/267408-array-sorting-based-on-another-array/#findComment-1371725 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.