数组运用技巧

时间:2022-12-05 15:58:39
$a = Array
(
[0] => Array
(
[date] => 2019-12-02
[time] => 1575216000
[week] => 周一
) [1] => Array
(
[date] => 2019-12-03
[time] => 1575302400
[week] => 周二
) [2] => Array
(
[date] => 2019-12-04
[time] => 1575388800
[week] => 周三
) [3] => Array
(
[date] => 2019-12-05
[time] => 1575475200
[week] => 周四
) [4] => Array
(
[date] => 2019-12-06
[time] => 1575561600
[week] => 周五
) [5] => Array
(
[date] => 2019-12-07
[time] => 1575648000
[week] => 周六
) [6] => Array
(
[date] => 2019-12-08
[time] => 1575734400
[week] => 周日
))
$b = Array
(
[0] => 公司
[1] => 公司
[2] => 公司
[3] => 公司
[4] => 公司
[5] => 公司
[6] => 休息
)需要将数组b的值拼接到数组a对应的Key的值
foreach($a as $key=>$val) {
foreach($b as $k=>$value){
$a[$k]['content'] = $value;
}
}//拼接后的结果
Array
(
[0] => Array
(
[date] => 2019-12-02
[time] => 1575216000
[week] => 周一
[content] => 公司
) [1] => Array
(
[date] => 2019-12-03
[time] => 1575302400
[week] => 周二
[content] => 公司
) [2] => Array
(
[date] => 2019-12-04
[time] => 1575388800
[week] => 周三
[content] => 公司
) [3] => Array
(
[date] => 2019-12-05
[time] => 1575475200
[week] => 周四
[content] => 公司
) [4] => Array
(
[date] => 2019-12-06
[time] => 1575561600
[week] => 周五
[content] => 公司
) [5] => Array
(
[date] => 2019-12-07
[time] => 1575648000
[week] => 周六
[content] => 公司
) [6] => Array
(
[date] => 2019-12-08
[time] => 1575734400
[week] => 周日
[content] => 休息
))