<?php
// echo strtotime("2018-04-01 17:56").'<br/>';
// echo strtotime("2018-05-31 17:56");
header("content-type:text/html;charset=utf-8");
$arr = array(
array(
'count_num' =>'71',
'new_time' =>'04.12',
),
array(
'count_num' =>'1647',
'new_time' =>'04.13',
),
array(
'count_num' =>'149',
'new_time' =>'04.14',
),
array(
'count_num' =>'94',
'new_time' =>'04.15',
),
array(
'count_num' =>'194',
'new_time' =>'04.17',
),
);
$a = array(
'04.17',
'04.16',
'04.15',
'04.14',
'04.13',
'04.12',
'04.11',
);
/**
*查询结果处理
*$arr是数据库查询出来的结果集合
*$a是日期
*/
function test($arr,$a){
$star_names = array_column($arr, 'count_num');
$last_names = array_column($arr, 'new_time');
$trans = array_flip($last_names);
for($i = 0;$i < count($a);$i++){
if(in_array($a[$i],$last_names)){
$result[] = $star_names[$trans[$a[$i]]];
}else{
$result[] = 0;
}
}
return $result;
}
$a = test($arr,$a);
var_dump($a);