php数组循环合并的问题!
有这样的很多的数组,Array('date'=>2011-11-30,'week'=>周三001);Array('date'=>2011-11-30,'week'=>周三...
有这样的很多的数组,
Array('date' => 2011-11-30,'week' => 周三001);
Array('date' => 2011-11-30,'week' => 周三002);
Array('date' => 2011-11-30,'week' => 周三003);
Array('date' => 2011-12-01,'week' => 周四001);
Array('date' => 2011-12-01,'week' => 周四002);
Array('date' => 2011-12-01,'week' => 周四003);
Array('date' => 2011-12-02''week' => 周五001);
Array('date' => 2011-12-02,'week' => 周五002);
Array('date' => 2011-12-02,'week' => 周五003);
Array('date' => 2011-12-03,'week' => 周六001);
Array('date' => 2011-12-03,'week' => 周六002);
..........
合并成类似这样数组
$weekDate = arr(Array('date' => 2011-11-30,'week' => 星期三),Array('date' => 2011-12-01,'week' => 星期四),Array('date' => 2011-12-02,'week' => 星期五),Array('date' => 2011-12-03,'week' => 星期六)) 展开
Array('date' => 2011-11-30,'week' => 周三001);
Array('date' => 2011-11-30,'week' => 周三002);
Array('date' => 2011-11-30,'week' => 周三003);
Array('date' => 2011-12-01,'week' => 周四001);
Array('date' => 2011-12-01,'week' => 周四002);
Array('date' => 2011-12-01,'week' => 周四003);
Array('date' => 2011-12-02''week' => 周五001);
Array('date' => 2011-12-02,'week' => 周五002);
Array('date' => 2011-12-02,'week' => 周五003);
Array('date' => 2011-12-03,'week' => 周六001);
Array('date' => 2011-12-03,'week' => 周六002);
..........
合并成类似这样数组
$weekDate = arr(Array('date' => 2011-11-30,'week' => 星期三),Array('date' => 2011-12-01,'week' => 星期四),Array('date' => 2011-12-02,'week' => 星期五),Array('date' => 2011-12-03,'week' => 星期六)) 展开
1个回答
展开全部
$all_arr = array(
Array('date' => '2011-11-30','week' => '周三001'),
Array('date' => '2011-11-30','week' => '周三002'),
Array('date' => '2011-11-30','week' => '周三003'),
Array('date' => '2011-12-01','week' => '周四001'),
Array('date' => '2011-12-01','week' => '周四002'),
Array('date' => '2011-12-01','week' => '周四003'),
Array('date' => '2011-12-02','week' => '周五001'),
Array('date' => '2011-12-02','week' => '周五002'),
Array('date' => '2011-12-02','week' => '周五003'),
Array('date' => '2011-12-03','week' => '周六001'),
Array('date' => '2011-12-03','week' => '周六002'),
);
$weekDate[] = array('date' => $all_arr[0]['date'],'week' => substr($all_arr[$i+1]['week'], 0, -3));
for($i = 0; $i < count($all_arr) -1; $i++ )
{
if($all_arr[$i]['date'] != $all_arr[$i+1]['date'])
{
$weekDate[] = array('date' => $all_arr[$i+1]['date'],'week' => substr($all_arr[$i+1]['week'], 0, -3));
}
}
Array('date' => '2011-11-30','week' => '周三001'),
Array('date' => '2011-11-30','week' => '周三002'),
Array('date' => '2011-11-30','week' => '周三003'),
Array('date' => '2011-12-01','week' => '周四001'),
Array('date' => '2011-12-01','week' => '周四002'),
Array('date' => '2011-12-01','week' => '周四003'),
Array('date' => '2011-12-02','week' => '周五001'),
Array('date' => '2011-12-02','week' => '周五002'),
Array('date' => '2011-12-02','week' => '周五003'),
Array('date' => '2011-12-03','week' => '周六001'),
Array('date' => '2011-12-03','week' => '周六002'),
);
$weekDate[] = array('date' => $all_arr[0]['date'],'week' => substr($all_arr[$i+1]['week'], 0, -3));
for($i = 0; $i < count($all_arr) -1; $i++ )
{
if($all_arr[$i]['date'] != $all_arr[$i+1]['date'])
{
$weekDate[] = array('date' => $all_arr[$i+1]['date'],'week' => substr($all_arr[$i+1]['week'], 0, -3));
}
}
更多追问追答
追问
但是那些数组都是单个的啊,怎么样把它们放到一个大数组里面呢?
追答
楼主自己去看看 数组函数吧.
都已经写成这样了还看不懂 手册有木有啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询