Home > Backend Development > PHP Tutorial > php数组合并解决方案

php数组合并解决方案

WBOY
Release: 2016-06-13 12:26:21
Original
964 people have browsed it

php数组合并

<br />$a=Array<br />(<br />    [0] => Array<br />        (<br />            [newsupdate_id] => 1<br />        )<br />    [1] => Array<br />        (<br />            [newsupdate_id] => 2<br />        )<br />}<br />  <br />$b=Array<br />(<br />    [0] => 张三<br />    [1] => 李四<br />}<br />  <br />想要的结果<br />$c=Array<br />(<br />    [0] => Array<br />        (<br />            [newsupdate_id] => 1<br />            [newsupdate_name] => 张三<br />        )<br />    [1] => Array<br />        (<br />            [newsupdate_id] => 2<br />            [newsupdate_name] => 李四<br />        )<br />}<br />
Copy after login

------解决思路----------------------
这样更一般
$a = array(<br />  array('newsupdate_id' => 1),<br />  array('newsupdate_id' => 2),<br />);<br />   <br />$b = array('张三', '李四');<br /><br />foreach($a as $i=>$v) {<br />  $c[] = array_merge($v, array('newsupdate_name' => $b[$i]));<br />}<br />print_r($c);
Copy after login
Array<br />(<br />    [0] => Array<br />        (<br />            [newsupdate_id] => 1<br />            [newsupdate_name] => 张三<br />        )<br /><br />    [1] => Array<br />        (<br />            [newsupdate_id] => 2<br />            [newsupdate_name] => 李四<br />        )<br /><br />)<br /><br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template