两组多行数据怎么整合在一起,每行对应
程序员文章站
2024-01-28 11:14:16
...
比如
b第一个是空行
要先去掉B的第一个空行
要这样对应
第001|||52-->10362/001
第002|||40-->10362/002
``````````````````
第012|||40-->10362/012
B的值第一个主要是个空行,可以按你说的写个代码出来吗
感谢,请问要怎么输出字符串,而不是数组?
第001|||52>>>>>>>10362/001
第002|||40>>>>>>>10362/002
``````````````````
第012|||40>>>>>>>10362/012
输出这样的字符串
$a='第001|||52第002|||40第003|||40第004|||44第005|||38第006|||40第007|||40第008|||40第009|||40第010|||36第011|||40第012|||40';$b='10362/00110362/00210362/00310362/00410362/00510362/00610362/00710362/00810362/00910362/01010362/01110362/012';
b第一个是空行
要先去掉B的第一个空行
要这样对应
第001|||52-->10362/001
第002|||40-->10362/002
``````````````````
第012|||40-->10362/012
回复讨论(解决方案)
组装数组咯 以$a的值作为键,$b作为值。。没试验过~
组装数组咯 以$a的值作为键,$b作为值。。没试验过~
B的值第一个主要是个空行,可以按你说的写个代码出来吗
$a='第001|||52第002|||40第003|||40第004|||44第005|||38第006|||40第007|||40第008|||40第009|||40第010|||36第011|||40第012|||40';$b='10362/00110362/00210362/00310362/00410362/00510362/00610362/00710362/00810362/00910362/01010362/01110362/012';$a1 = preg_split("/[\r\n]+/", trim($a));$b1 = preg_split("/[\r\n]+/", trim($b));print_r(array_combine($a1, $b1));//或print_r(array_map(null, $a1, $b1));
Array( [第001|||52] => 10362/001 [第002|||40] => 10362/002 [第003|||40] => 10362/003 [第004|||44] => 10362/004 [第005|||38] => 10362/005 [第006|||40] => 10362/006 [第007|||40] => 10362/007 [第008|||40] => 10362/008 [第009|||40] => 10362/009 [第010|||36] => 10362/010 [第011|||40] => 10362/011 [第012|||40] => 10362/012)Array( [0] => Array ( [0] => 第001|||52 [1] => 10362/001 ) [1] => Array ( [0] => 第002|||40 [1] => 10362/002 ) [2] => Array ( [0] => 第003|||40 [1] => 10362/003 ) [3] => Array ( [0] => 第004|||44 [1] => 10362/004 ) [4] => Array ( [0] => 第005|||38 [1] => 10362/005 ) [5] => Array ( [0] => 第006|||40 [1] => 10362/006 ) [6] => Array ( [0] => 第007|||40 [1] => 10362/007 ) [7] => Array ( [0] => 第008|||40 [1] => 10362/008 ) [8] => Array ( [0] => 第009|||40 [1] => 10362/009 ) [9] => Array ( [0] => 第010|||36 [1] => 10362/010 ) [10] => Array ( [0] => 第011|||40 [1] => 10362/011 ) [11] => Array ( [0] => 第012|||40 [1] => 10362/012 ))
$a='第001|||52第002|||40第003|||40第004|||44第005|||38第006|||40第007|||40第008|||40第009|||40第010|||36第011|||40第012|||40';$b='10362/00110362/00210362/00310362/00410362/00510362/00610362/00710362/00810362/00910362/01010362/01110362/012';$a1 = preg_split("/[\r\n]+/", trim($a));$b1 = preg_split("/[\r\n]+/", trim($b));print_r(array_combine($a1, $b1));//或print_r(array_map(null, $a1, $b1));
Array( [第001|||52] => 10362/001 [第002|||40] => 10362/002 [第003|||40] => 10362/003 [第004|||44] => 10362/004 [第005|||38] => 10362/005 [第006|||40] => 10362/006 [第007|||40] => 10362/007 [第008|||40] => 10362/008 [第009|||40] => 10362/009 [第010|||36] => 10362/010 [第011|||40] => 10362/011 [第012|||40] => 10362/012)Array( [0] => Array ( [0] => 第001|||52 [1] => 10362/001 ) [1] => Array ( [0] => 第002|||40 [1] => 10362/002 ) [2] => Array ( [0] => 第003|||40 [1] => 10362/003 ) [3] => Array ( [0] => 第004|||44 [1] => 10362/004 ) [4] => Array ( [0] => 第005|||38 [1] => 10362/005 ) [5] => Array ( [0] => 第006|||40 [1] => 10362/006 ) [6] => Array ( [0] => 第007|||40 [1] => 10362/007 ) [7] => Array ( [0] => 第008|||40 [1] => 10362/008 ) [8] => Array ( [0] => 第009|||40 [1] => 10362/009 ) [9] => Array ( [0] => 第010|||36 [1] => 10362/010 ) [10] => Array ( [0] => 第011|||40 [1] => 10362/011 ) [11] => Array ( [0] => 第012|||40 [1] => 10362/012 ))
$a='第001|||52第002|||40第003|||40第004|||44第005|||38第006|||40第007|||40第008|||40第009|||40第010|||36第011|||40第012|||40';$b='10362/00110362/00210362/00310362/00410362/00510362/00610362/00710362/00810362/00910362/01010362/01110362/012';$a1 = preg_split("/[\r\n]+/", trim($a));$b1 = preg_split("/[\r\n]+/", trim($b));print_r(array_combine($a1, $b1));//或print_r(array_map(null, $a1, $b1));
Array( [第001|||52] => 10362/001 [第002|||40] => 10362/002 [第003|||40] => 10362/003 [第004|||44] => 10362/004 [第005|||38] => 10362/005 [第006|||40] => 10362/006 [第007|||40] => 10362/007 [第008|||40] => 10362/008 [第009|||40] => 10362/009 [第010|||36] => 10362/010 [第011|||40] => 10362/011 [第012|||40] => 10362/012)Array( [0] => Array ( [0] => 第001|||52 [1] => 10362/001 ) [1] => Array ( [0] => 第002|||40 [1] => 10362/002 ) [2] => Array ( [0] => 第003|||40 [1] => 10362/003 ) [3] => Array ( [0] => 第004|||44 [1] => 10362/004 ) [4] => Array ( [0] => 第005|||38 [1] => 10362/005 ) [5] => Array ( [0] => 第006|||40 [1] => 10362/006 ) [6] => Array ( [0] => 第007|||40 [1] => 10362/007 ) [7] => Array ( [0] => 第008|||40 [1] => 10362/008 ) [8] => Array ( [0] => 第009|||40 [1] => 10362/009 ) [9] => Array ( [0] => 第010|||36 [1] => 10362/010 ) [10] => Array ( [0] => 第011|||40 [1] => 10362/011 ) [11] => Array ( [0] => 第012|||40 [1] => 10362/012 ))
感谢,请问要怎么输出字符串,而不是数组?
你要按什么格式输出?
你要按什么格式输出?
第001|||52>>>>>>>10362/001
第002|||40>>>>>>>10362/002
``````````````````
第012|||40>>>>>>>10362/012
输出这样的字符串
foreach(array_combine($a1, $b1) as $k=>$v) $r[] = "$k>>>>>>>$v";echo join(PHP_EOL, $r);//或echo join(PHP_EOL, array_map(function($a, $b) {return "$a>>>>>>>$b";}, $a1, $b1));
上一篇: php和html混编
下一篇: Linux下的PHP开发环境
推荐阅读