This article mainly introduces the method of formatting seconds with PHP custom functions, involving the operation skills of PHP arrays and numerical operations. Friends in need can refer to it
The details are as follows:
function vtime($time) { $output = ''; foreach (array(86400 => '天', 3600 => '小时', 60 => '分', 1 => '秒') as $key => $value) { if ($time >= $key) $output .= floor($time/$key) . $value; $time %= $key; } if($output==''){ $output=0; } return $output; } //$now=time(); $oldtime=86465; //echo vtime($now);//输出:17058天4小时8分55秒 echo vtime($oldtime);//输出:1天1分5秒
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHP method to implement two-dimensional array sorting by a certain column_phpTips
php Implementing Baidu weather forecast for WeChat development
PHP method to achieve batch acquisition of all fixed seed links in web pages
The above is the detailed content of PHP method to implement formatting seconds based on custom function. For more information, please follow other related articles on the PHP Chinese website!