首页 > 后端开发 > php教程 > php 合龙两个二维数组

php 合龙两个二维数组

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-13 13:00:27
原创
830 人浏览过

php 合并两个二维数组
按时间排序的

<br />
<br />
$data1 = array(<br />
<br />
    [0] => array(<br />
        times => '2012-10-10',<br />
        type =>0,<br />
        num =>100<br />
    ),<br />
<br />
    [1] => array(<br />
        times => '2012-10-11',<br />
        type =>0,<br />
        num =>103<br />
    ),<br />
<br />
  ....<br />
       <br />
)<br />
<br />
$data2 = array(<br />
<br />
    [0] => array(<br />
        times => '2012-10-10',<br />
        type =>1,<br />
        num =>400<br />
    ),<br />
<br />
    [1] => array(<br />
        times => '2012-10-11',<br />
        type =>1,<br />
        num =>403<br />
    ),<br />
<br />
  ....<br />
       <br />
)<br />
<br />
登录后复制


两个数组times 是一样的,怎么把它们合并成

<br />
$data = array(<br />
<br />
    [0] => array(<br />
        times => '2012-10-10',<br />
        type =>0,<br />
        num =>100<br />
        type =>1,<br />
        num =>400<br />
    ),<br />
<br />
    [1] => array(<br />
        times => '2012-10-11',<br />
        type =>0,<br />
        num =>103<br />
        type =>1,<br />
        num =>403<br />
    ),<br />
<br />
  ....<br />
       <br />
)<br />
登录后复制


求教

------解决方案--------------------
楼主,就冲你那0的结贴率,呵呵。
<br />
 $date=array(array("time"=>"2012-11-10","type0"=>0,"num0"=>100),array("time"=>"2012-11-11","type0"=>0,"num0"=>103));<br />
 $date1=array(array("time"=>"2012-11-10","type1"=>1,"num1"=>105),array("time"=>"2012-11-11","type1"=>1,"num1"=>120));<br />
 $cnt=count($date);<br />
 for($i=0;$i<$cnt;$i++){<br />
	$date2[$i]=array_merge($date[$i],$date1[$i]);<br />
}<br />
 echo "<pre class="brush:php;toolbar:false">";<br />
 print_r($date);<br />
 print_r($date1);<br />
 print_r($date2);<br />
 echo "
登录后复制
";
//结果如下
Array
(
    [0] => Array
        (
            [time] => 2012-11-10
            [type0] => 0
            [num0] => 100
        )

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板