欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 合龙两个二维数组

程序员文章站 2024-01-16 14:08:58
...
php 合并两个二维数组
按时间排序的



$data1 = array(

[0] => array(
times => '2012-10-10',
type =>0,
num =>100
),

[1] => array(
times => '2012-10-11',
type =>0,
num =>103
),

....

)

$data2 = array(

[0] => array(
times => '2012-10-10',
type =>1,
num =>400
),

[1] => array(
times => '2012-10-11',
type =>1,
num =>403
),

....

)



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


$data = array(

[0] => array(
times => '2012-10-10',
type =>0,
num =>100
type =>1,
num =>400
),

[1] => array(
times => '2012-10-11',
type =>0,
num =>103
type =>1,
num =>403
),

....

)


求教

------解决方案--------------------
楼主,就冲你那0的结贴率,呵呵。

$date=array(array("time"=>"2012-11-10","type0"=>0,"num0"=>100),array("time"=>"2012-11-11","type0"=>0,"num0"=>103));
$date1=array(array("time"=>"2012-11-10","type1"=>1,"num1"=>105),array("time"=>"2012-11-11","type1"=>1,"num1"=>120));
$cnt=count($date);
for($i=0;$i $date2[$i]=array_merge($date[$i],$date1[$i]);
}
echo "
";
print_r($date);
print_r($date1);
print_r($date2);
echo "
";
//结果如下
Array
(
[0] => Array
(
[time] => 2012-11-10
[type0] => 0
[num0] => 100
)
php 合龙两个二维数组

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频