php中的自定义过滤器数组值
我正在尝试用PHP做一个过滤函数。我已经开始吼叫:php中的自定义过滤器数组值,php,Php,我正在尝试用PHP做一个过滤函数。我已经开始吼叫: function handleDuplicates($duplicateMonthReportsArray,$NodeReports,$whatToCompare){ foreach ($duplicateMonthReportsArray as $duplicate) { $duplicateReportsArray = $NodeReports->nodeReports[$duplicate]->indvR
function handleDuplicates($duplicateMonthReportsArray,$NodeReports,$whatToCompare){
foreach ($duplicateMonthReportsArray as $duplicate) {
$duplicateReportsArray = $NodeReports->nodeReports[$duplicate]->indvReports;
var_dump($duplicateReportsArray); //Prints out what I have written bellow
foreach ($duplicateReportsArray as $duplicateReport) {
if($whatToCompare==="both"){
//Return higest [NoSamples] and latest ["StopTime"] (If possible).
}
else if($whatToCompare==="latest"){
//Return array with latest ["StopTime"]
}else{
//Return array with higest [NoSamples] (If both same like the bellow case then return latest "StopTime")
}
}
}
}
array(2) {
[""AU Feb-13",201302282 "]=>
array(2) {
["StopTime"]=>
string(23) "2013-02-28 23:00:00.000"
["NoSamples"]=>
string(5) "673.0"
}
[""AU Feb-13",201302282 "]=>
array(2) {
["StopTime"]=>
string(23) "2013-02-28 23:55:00.000"
["NoSamples"]=>
string(5) "673.0"
}
}
var_dump会打印出以下内容:
function handleDuplicates($duplicateMonthReportsArray,$NodeReports,$whatToCompare){
foreach ($duplicateMonthReportsArray as $duplicate) {
$duplicateReportsArray = $NodeReports->nodeReports[$duplicate]->indvReports;
var_dump($duplicateReportsArray); //Prints out what I have written bellow
foreach ($duplicateReportsArray as $duplicateReport) {
if($whatToCompare==="both"){
//Return higest [NoSamples] and latest ["StopTime"] (If possible).
}
else if($whatToCompare==="latest"){
//Return array with latest ["StopTime"]
}else{
//Return array with higest [NoSamples] (If both same like the bellow case then return latest "StopTime")
}
}
}
}
array(2) {
[""AU Feb-13",201302282 "]=>
array(2) {
["StopTime"]=>
string(23) "2013-02-28 23:00:00.000"
["NoSamples"]=>
string(5) "673.0"
}
[""AU Feb-13",201302282 "]=>
array(2) {
["StopTime"]=>
string(23) "2013-02-28 23:55:00.000"
["NoSamples"]=>
string(5) "673.0"
}
}
我想做的是在代码中作为注释打印出来。我想做一个定制的过滤函数,它在一个对象数组中循环,这个数组看起来像我上面写的var_dump,或者返回具有最高停止时间、最高nosample或两者(如果可能)的数组实例,否则只返回最大的nosample
您将如何实现此filterfunction?在我的例子中,是否有任何已完成的筛选函数可以使用,它接受一个数组数组并对其执行筛选
非常感谢。假设$arrays变量包含您的var\u转储数据:
$maxStopTime = "";
$maxStopTimeIx = 0;
$maxNoSamples = "";
$maxNoSamplesIx = 0;
foreach ($arrays as $k=>$array) {
if ($array['StopTime'] > $maxStopTime) {
$maxStopTimeIx = $k;
$maxStopTime = $array['StopTime'];
}
if ($array['NoSamples'] > $maxNoSamples) {
$maxNoSamplesIx = $k;
$maxNoSamples = $array['NoSamples'];
}
}
$maxStopTimeArray = $arrays[$maxStopTimeIx];
$maxNoSamplesArray = $arrays[$maxNoSamplesIx];