search
HomeBackend DevelopmentPHP Tutorial两组多行数据怎么整合在一起,每行对应

比如

$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));

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.