How to integrate two sets of multi-row data?
$ A = '1970 | 52 001st | 40 002nd | 40 003rd | 44 004th | 38 005th | 40 006th | 40 007th | 40 008th | 40 009th | 40 010th | 36 011st | 40 012nd | 40 '; $ B = '2014/1/0/0/2/10362/00110362/00210362/00310362/0/012 ';
B. The first line is empty.
Remove the first blank line of B first.
To match
001st | 52 --> 10362/001
002nd | 40 --> 10362/002
""""""
012nd | 40 --> 10362/012
Reply to discussion (solution)
The assembled array uses the value of $ a as the key and $ B as the value .. No tests ~
The assembled array uses the value of $ a as the key and $ B as the value .. No tests ~
The first value of B is mainly a blank line. can I write a code as you said?
$ A = '1970 | 52 001st | 40 002nd | 40 003rd | 44 004th | 38 005th | 40 006th | 40 007th | 40 008th | 40 009th | 40 010th | 36 011st | 40 012nd | 40 '; $ B = '2014/1/0/0/2/0/2/0/0/12 '; $ a1 = preg_split ("/[\ r \ n] + /", trim ($ a); $ b1 = preg_split ("/[\ r \ n] +/", trim ($ B); print_r (array_combine ($ a1, $ b1); // or print_r (array_map (null, $ a1, $ b1 ));
Array ([001st | 52] => 10362/001 [002nd | 40] => 10362/002 [003rd | 40] => 10362/003 [004th | 44] => 10362/004 [005th | 38] => 10362/005 [006th | 40] => 10362/006 [007th | 40] => 10362/007 [008th | 40] => 10362/008 [009th | 40] => 10362/009 [010th | 36] => 10362/010 [011st | 40] => 10362/011 [012nd | 40] => 10362/012) array ([0] => Array ([0] => 001st | 52 [1] => 10362/001) [1] => Array ([0] => 002nd | 40 [1] => 10362/002) [2] => Array ([0] => 003rd | 40 [1] => 10362/003) [3] => Array ([0] => 004th | 44 [1] => 10362/004) [4] => Array ([0] => 005th | 38 [1] => 10362/005) [5] => Array ([0] => 006th | 40 [1] => 10362/006) [6] => Array ([0] => 007th | 40 [1] => 10362/007) [7] => Array ([0] => 008th | 40 [1] => 10362/008) [8] => Array ([0] => 009th | 40 [1] => 10362/009) [9] => Array ([0] => 010th | 36 [1] => 10362/010) [10] => Array ([0] => 011st | 40 [1] => 10362/011) [11] => Array ([0] => 012nd | 40 [1] => 10362/012 ))
$ A = '1970 | 52 001st | 40 002nd | 40 003rd | 44 004th | 38 005th | 40 006th | 40 007th | 40 008th | 40 009th | 40 010th | 36 011st | 40 012nd | 40 '; $ B = '2014/1/0/0/2/0/2/0/0/12 '; $ a1 = preg_split ("/[\ r \ n] + /", trim ($ a); $ b1 = preg_split ("/[\ r \ n] +/", trim ($ B); print_r (array_combine ($ a1, $ b1); // or print_r (array_map (null, $ a1, $ b1 ));
Array ([001st | 52] => 10362/001 [002nd | 40] => 10362/002 [003rd | 40] => 10362/003 [004th | 44] => 10362/004 [005th | 38] => 10362/005 [006th | 40] => 10362/006 [007th | 40] => 10362/007 [008th | 40] => 10362/008 [009th | 40] => 10362/009 [010th | 36] => 10362/010 [011st | 40] => 10362/011 [012nd | 40] => 10362/012) array ([0] => Array ([0] => 001st | 52 [1] => 10362/001) [1] => Array ([0] => 002nd | 40 [1] => 10362/002) [2] => Array ([0] => 003rd | 40 [1] => 10362/003) [3] => Array ([0] => 004th | 44 [1] => 10362/004) [4] => Array ([0] => 005th | 38 [1] => 10362/005) [5] => Array ([0] => 006th | 40 [1] => 10362/006) [6] => Array ([0] => 007th | 40 [1] => 10362/007) [7] => Array ([0] => 008th | 40 [1] => 10362/008) [8] => Array ([0] => 009th | 40 [1] => 10362/009) [9] => Array ([0] => 010th | 36 [1] => 10362/010) [10] => Array ([0] => 011st | 40 [1] => 10362/011) [11] => Array ([0] => 012nd | 40 [1] => 10362/012 ))
$ A = '1970 | 52 001st | 40 002nd | 40 003rd | 44 004th | 38 005th | 40 006th | 40 007th | 40 008th | 40 009th | 40 010th | 36 011st | 40 012nd | 40 '; $ B = '2014/1/0/0/2/0/2/0/0/12 '; $ a1 = preg_split ("/[\ r \ n] + /", trim ($ a); $ b1 = preg_split ("/[\ r \ n] +/", trim ($ B); print_r (array_combine ($ a1, $ b1); // or print_r (array_map (null, $ a1, $ b1 ));
Array ([001st | 52] => 10362/001 [002nd | 40] => 10362/002 [003rd | 40] => 10362/003 [004th | 44] => 10362/004 [005th | 38] => 10362/005 [006th | 40] => 10362/006 [007th | 40] => 10362/007 [008th | 40] => 10362/008 [009th | 40] => 10362/009 [010th | 36] => 10362/010 [011st | 40] => 10362/011 [012nd | 40] => 10362/012) array ([0] => Array ([0] => 001st | 52 [1] => 10362/001) [1] => Array ([0] => 002nd | 40 [1] => 10362/002) [2] => Array ([0] => 003rd | 40 [1] => 10362/003) [3] => Array ([0] => 004th | 44 [1] => 10362/004) [4] => Array ([0] => 005th | 38 [1] => 10362/005) [5] => Array ([0] => 006th | 40 [1] => 10362/006) [6] => Array ([0] => 007th | 40 [1] => 10362/007) [7] => Array ([0] => 008th | 40 [1] => 10362/008) [8] => Array ([0] => 009th | 40 [1] => 10362/009) [9] => Array ([0] => 010th | 36 [1] => 10362/010) [10] => Array ([0] => 011st | 40 [1] => 10362/011) [11] => Array ([0] => 012nd | 40 [1] => 10362/012 ))
Thank you. how can I output strings instead of arrays?
What format do you want to output?
What format do you want to output?
001st | 52 >>>>>> 10362/001
002nd | 40 >>>>>> 10362/002
""""""
012nd | 40 >>>>>> 10362/012
Output such a string
Foreach (array_combine ($ a1, $ b1) as $ k =>$ v) $ r [] = "$ k >>>>>>>$ v "; echo join (PHP_EOL, $ r); // or echo join (PHP_EOL, array_map (function ($ a, $ B) {return "$ a >>>>>>>> $ B" ;}, $ a1, $ b1 ));