PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $timestamps = array(); for ($i = 0; $i < 50; $i++) { $timestamps[] = mt_rand(strtotime('1900-01-01'), strtotime('2100-12-31 11:59:59 pm')); } $res = array_reduce( $timestamps, function($res, $t) { $time = date('H:i:s', $t); if (is_null($res['min'][0]) || $time<$res['min'][0]) $res['min'] = [$time, date('Y-m-d h:i:s a', $t)]; if (is_null($res['max'][0]) || $time>$res['max'][0]) $res['max'] = [$time, date('Y-m-d h:i:s a', $t)]; return $res; }, ['min'=>[null, null], 'max'=>[null, null]] ); print_r($res); $mapped = array_map( function($t) { return [date('H:i:s', $t), date('Y-m-d h:i:s a', $t)]; }, $timestamps ); print_r(array_column($mapped, 1, 0));
Show:  
Copy Clear