首先,我想提前感谢您的帮助。
我有一个像这样结构的数组:
array(18) {
["department"]=>
string(14) "Administration"
["employee"]=>
string(13) "Joe Smith"
["times"]=>
string(6) "7:00am"
["timee"]=>
string(6) "7:00pm"
["regular"]=>
int(8)
["overtime"]=>
int(4)
["d_overtime"]=>
int(4)
["total"]=>
int(12)
["cost"]=>
int(28)
["date"]=>
string(12) "May 27, 2014"
["curdp"]=>
int(28)
["mtddp"]=>
int(28)
["rev"]=>
string(10) "35073.8900"
["dp2rev"]=>
string(5) "0.08%"
["mtd2rev2013"]=>
string(4) "-na-"
["mtdpay2rev"]=>
string(5) "0.08%"
["budget"]=>
string(4) "1.80"
["counter"]=>
NULL
}
我需要能够找到具有相同“日期”值的数组中的最后一个条目。例如,我需要在数组中找到所有May 27,2014值并显示最后一个条目。
再次感谢你。
答案 0 :(得分:0)
让输入数据在$ data
中$resultArr = array();
$filteredByDateArr = array();
foreach($data as $entry)
{
if($entry['date']=='May 27, 2014')
$resultArr[] = $entry;
$filteredByDateArr[$entry['date']][] = $entry;
}
//last entry
var_dump($resultArr[count($resultArr)-1]);
var_dump($filteredByDateArr);
//This $filteredByDateArr is the array that will give you date respective data.
//So if you want to find the last entry of say any date $date
//You can get it by:
var_dump($filteredByDateArr[$date][count($filteredByDateArr[$date])-1]);