php - Need a way to output merged content from two arrays -


i have 2 large arrays want recognize finds duplicates on first array, , merges them exact array position in array, , append value comma. cannot wrap head around how it.

//array multiple entries. $applicationid = array('1','1','2','3','3','4','5','6','6','7','8','9','10','11','12','13','13','14','14','15','16','17','18','18'); $applicantid = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','11','22','25'); 

easily viewed looks when put side side.

applicationid on left.  applicantid on right.     1   1     1   2     2   3     3   4     3   5     4   6     5   7     6   8     6   9     7   10     8   11     9   12     10  13     11  14     12  15     13  16     13  17     14  18     14  19     15  20     16  21     17  11     18  22     18  25 

i end result these 2 arrays:

[1]['1,2'] [2]['3'] [3]['4,5'] [4]['6'] [5]['7'] [6]['8,9'] [7]['10'] [8]['11'] [9]['12'] [10]['13'] [11]['14'] [12]['15'] [13]['16,17'] [14]['18,19'] [15]['20'] [16]['21'] [17]['11'] [18]['22,25'] 

i'm sure easy out there cannot seem able wrap head around or understand syntax required.

additionally note arrays bigger (roughly 1400 or entries).

it's quite simple. that's convenient indexes match (whilst says data generated in not suitable format).

try merging them this:

$applicationid = array('1','1','2','3','3','4','5','6','6','7','8','9','10','11','12','13','13','14','14','15','16','17','18','18'); $applicantid = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','11','22','25');  $applicantsbyapplications = []; $applicantscount = count($applicationid); ($i = 0; $i < $applicantscount; $i++) {     $applicant = $applicantid[$i];     $application = $applicationid[$i];     if (!isset($applicantsbyapplications[$application]))         $applicantsbyapplications[$application] = [];     $applicantsbyapplications[$application][] = $applicant; } 

this can beautified using standard functions, array_map etc., principle stays same.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -