【发布时间】:2019-07-17 19:53:16
【问题描述】:
我的数组是 $arrIncome 和 $arrExpense。他们有一些相同的日期和一些不同的日期。
$arrIncome = [
[
'date' => '01-01-2019',
'total' => '500',
],
[
'date' => '02-01-2019',
'total' => '200',
],
[
'date' => '03-01-2019',
'total' => '300',
],
[
'date' => '04-01-2019',
'total' => '900',
],
];
$arrExpense= [
[
'date' => '01-01-2019',
'total' => '50',
],
[
'date' => '02-01-2019',
'total' => '60',
],
[
'date' => '07-01-2019',
'total' => '25',
],
[
'date' => '08-01-2019',
'total' => '50',
],
];
我在 $arrIncome 数组中循环,如果我发现 $arrExpense 数组中有收入日期,我将按 $arrIncome 的收入日期删除 $arrExpense 中的一个数组,因为我想制作唯一的日期。
foreach ($arrIncome as $income){
$isExistExpense = array_filter($arrExpense, function($expense) use($income){
return $expense->date == date('Y-m-d', strtotime($income->date));
});
if(count($isExistExpense) > 0 ){
foreach ($isExistExpense as $expense){
// THIS PLACE TO UNSET $arrExpense by date value
unset($arrExpense['date'] = $income->date); // this is a wrong way
}
}else{
// my code more here.....
}
}
【问题讨论】:
-
你有什么问题?
-
如何通过键和值取消设置数组?
-
我认为它与我想要的不一样。数组不一样