我很困惑,我是 php 新手。我正在使用此代码获取状态为未付款且所用时间(以天为单位)为 >30 或 >60 或 >90 天的列表。如果花费的时间>30 天,则颜色应为蓝色,>60 天,则颜色应为橙色,如果>90 天,则颜色应为红色。所有条件都正常,但问题是我没有按照我想要的正确格式获得数组。
我的代码是
foreach ($listview_entries as $key => $value){
$invoice_focus = new Invoice();
$invoice_focus->id = $key;
$invoice_focus->retrieve_entity_info($key, "Invoice");
$invoicestatus = $invoice_focus->column_fields['invoicestatus'];
$invoicedate = $invoice_focus->column_fields['invoicedate'];
$currentdate = date("Y-m-d");
$start_date2 = strtotime($invoicedate);
$end_date2 = strtotime($currentdate);
$difference = $end_date2 - $start_date2;
$days = floor($difference/86400);
$items = array();
$color1 = array();
if($invoicestatus == 'Unpaid' && $days>30)
{
if($days>60)
{
if($days>90)
{
$milan=array($key);
$color=array_fill_keys($milan, 'red');
//$smarty->assign('COLOR', $color);
}
else
{
$milan=array($key);
$color=array_fill_keys($milan, 'orange');
//$smarty->assign('COLOR', $color);
}
}
else
{
$milan=array($key);
$color=array_fill_keys($milan, 'blue');
//$smarty->assign('COLOR', $color);
}
if(!empty($color)){
array_push($color1,$color);
}
print_r($color1);
}
$smarty->assign('COLOR', $color1);
}
我得到这样的输出。
Array ( [0] => Array ( [89] => red ) ) Array ( [0] => Array ( [91] => blue ) ) Array ( [0] => Array ( [92] => orange ) )
但我想要这样。
Array ( [0] => Array ( [89] => red ),[1] => Array ( [91] => blue ),[2] => Array ( [92] => orange ) )
请帮帮我。