php将两个二维数组按具有相同值合并
数组一:array(5){[0]=>array(3){["id"]=>string(4)"1"["date"]=>string(10)"2018-08-31"["time...
数组一:
array(5) {
[0]=>
array(3) {
["id"]=>
string(4) "1"
["date"]=>
string(10) "2018-08-31"
["time"]=>
string(10) "1532770482"
}
[1]=>
array(3) {
["id"]=>
string(4) "2"
["date"]=>
string(10) "2018-09-2"
["time"]=>
string(10) "1534920401"
}
[2]=>
array(3) {
["id"]=>
string(4) "3"
["date"]=>
string(10) "2018-09-3"
["time"]=>
string(10) "1534920401"
}
[3]=>
array(3) {
["id"]=>
string(4) "4"
["date"]=>
string(10) "2018-09-5"
["time"]=>
string(10) "1534920401"
}
[4]=>
array(3) {
["id"]=>
string(4) "5"
["date"]=>
string(10) "2018-09-6"
["time"]=>
string(10) "1534920401"
}
}
数组二:
array(8) {
[0]=>
array(3) {
["id"]=>
int(0)
["date"]=>
string(10) "2018-08-30"
["week"]=>
string(9) "星期四"
}
[1]=>
array(3) {
["id"]=>
int(1)
["date"]=>
string(10) "2018-08-31"
["week"]=>
string(9) "星期五"
}
[2]=>
array(3) {
["id"]=>
int(2)
["date"]=>
string(10) "2018-09-01"
["week"]=>
string(9) "星期六"
}
[3]=>
array(3) {
["id"]=>
int(3)
["date"]=>
string(10) "2018-09-02"
["week"]=>
string(9) "星期日"
}
[4]=>
array(3) {
["id"]=>
int(4)
["date"]=>
string(10) "2018-09-03"
["week"]=>
string(9) "星期一"
}
[5]=>
array(3) {
["id"]=>
int(5)
["date"]=>
string(10) "2018-09-04"
["week"]=>
string(9) "星期二"
}
[6]=>
array(3) {
["id"]=>
int(6)
["date"]=>
string(10) "2018-09-05"
["week"]=>
string(9) "星期三"
}
[7]=>
array(3) {
["id"]=>
int(7)
["date"]=>
string(10) "2018-09-06"
["week"]=>
string(9) "星期四"
}
}
现在想将数组一和二 合并 按date相同合并 请大神指教 展开
array(5) {
[0]=>
array(3) {
["id"]=>
string(4) "1"
["date"]=>
string(10) "2018-08-31"
["time"]=>
string(10) "1532770482"
}
[1]=>
array(3) {
["id"]=>
string(4) "2"
["date"]=>
string(10) "2018-09-2"
["time"]=>
string(10) "1534920401"
}
[2]=>
array(3) {
["id"]=>
string(4) "3"
["date"]=>
string(10) "2018-09-3"
["time"]=>
string(10) "1534920401"
}
[3]=>
array(3) {
["id"]=>
string(4) "4"
["date"]=>
string(10) "2018-09-5"
["time"]=>
string(10) "1534920401"
}
[4]=>
array(3) {
["id"]=>
string(4) "5"
["date"]=>
string(10) "2018-09-6"
["time"]=>
string(10) "1534920401"
}
}
数组二:
array(8) {
[0]=>
array(3) {
["id"]=>
int(0)
["date"]=>
string(10) "2018-08-30"
["week"]=>
string(9) "星期四"
}
[1]=>
array(3) {
["id"]=>
int(1)
["date"]=>
string(10) "2018-08-31"
["week"]=>
string(9) "星期五"
}
[2]=>
array(3) {
["id"]=>
int(2)
["date"]=>
string(10) "2018-09-01"
["week"]=>
string(9) "星期六"
}
[3]=>
array(3) {
["id"]=>
int(3)
["date"]=>
string(10) "2018-09-02"
["week"]=>
string(9) "星期日"
}
[4]=>
array(3) {
["id"]=>
int(4)
["date"]=>
string(10) "2018-09-03"
["week"]=>
string(9) "星期一"
}
[5]=>
array(3) {
["id"]=>
int(5)
["date"]=>
string(10) "2018-09-04"
["week"]=>
string(9) "星期二"
}
[6]=>
array(3) {
["id"]=>
int(6)
["date"]=>
string(10) "2018-09-05"
["week"]=>
string(9) "星期三"
}
[7]=>
array(3) {
["id"]=>
int(7)
["date"]=>
string(10) "2018-09-06"
["week"]=>
string(9) "星期四"
}
}
现在想将数组一和二 合并 按date相同合并 请大神指教 展开
2个回答
展开全部
开始 - 运行输入msconfig,回车,进入系统配置,点击:引导 - 高级选项,在处理器个数处,点击勾选4,确定,重启电脑。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$tmpArray = array();
foreach ($laArray as $row) {
$key = $row['name'] . $row['age'];
if (array_key_exists($key, $tmpArray)) {
$tmpArray[$key]['id'] = $tmpArray[$key]['id'] . '+' . $row['id'];
if (is_array($tmpArray[$key]['moeny'])) {
$tmpArray[$key]['moeny'][] = $row['moeny'];
} else {
$tmpArray[$key]['moeny'] = array($tmpArray[$key]['moeny'], $row['moeny']);
}
} else {
$tmpArray[$key] = $row;
}
}
echo "<pre>";
var_dump($tmpArray);
foreach ($laArray as $row) {
$key = $row['name'] . $row['age'];
if (array_key_exists($key, $tmpArray)) {
$tmpArray[$key]['id'] = $tmpArray[$key]['id'] . '+' . $row['id'];
if (is_array($tmpArray[$key]['moeny'])) {
$tmpArray[$key]['moeny'][] = $row['moeny'];
} else {
$tmpArray[$key]['moeny'] = array($tmpArray[$key]['moeny'], $row['moeny']);
}
} else {
$tmpArray[$key] = $row;
}
}
echo "<pre>";
var_dump($tmpArray);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询