ホームページ  >  記事  >  バックエンド開発  >  2 つの複数行データ セットを統合する方法。各行は以下に対応します。

2 つの複数行データ セットを統合する方法。各行は以下に対応します。

WBOY
WBOYオリジナル
2016-06-20 12:36:371143ブラウズ

たとえば、

$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 の最初の空行を削除する必要があります
これは対応する必要があります
No. 001 |||52-->10362/001
No.002|||40-->10362/002
``''''`````` ''''
No.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        ))



ありがとう、どうですか配列ではなく文字列を出力できますか?

どのような形式で出力しますか?

どのような形式で出力しますか?


No.001|||52>>>>>>>10362/001
No.002|||40>>>>>> > 10362/002
''''''''''''''
第 012 章|||40>>>>>>>>> 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));

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。