127 lines
4.6 KiB
PHP
127 lines
4.6 KiB
PHP
<?php
|
|
|
|
//兼容函数array_column PHP5.5+
|
|
if (!function_exists('array_column')) {
|
|
function array_column($input, $columnKey, $indexKey = NULL)
|
|
{
|
|
$columnKeyIsNumber = (is_numeric($columnKey)) ? TRUE : FALSE;
|
|
$indexKeyIsNull = (is_null($indexKey)) ? TRUE : FALSE;
|
|
$indexKeyIsNumber = (is_numeric($indexKey)) ? TRUE : FALSE;
|
|
$result = array();
|
|
foreach ((array)$input as $key => $row) {
|
|
if ($columnKeyIsNumber) {
|
|
$tmp = array_slice($row, $columnKey, 1);
|
|
$tmp = (is_array($tmp) && !empty($tmp)) ? current($tmp) : NULL;
|
|
} else {
|
|
$tmp = isset($row[ $columnKey ]) ? $row[ $columnKey ] : NULL;
|
|
}
|
|
if (!$indexKeyIsNull) {
|
|
if ($indexKeyIsNumber) {
|
|
$key = array_slice($row, $indexKey, 1);
|
|
$key = (is_array($key) && !empty($key)) ? current($key) : NULL;
|
|
$key = is_null($key) ? 0 : $key;
|
|
} else {
|
|
$key = isset($row[ $indexKey ]) ? $row[ $indexKey ] : 0;
|
|
}
|
|
}
|
|
$result[ $key ] = $tmp;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
# 计算时间差
|
|
# $begin_time 起始日期
|
|
# $end_time 结束日期 一般指当前日期
|
|
function timediff($begin_time, $end_time, $type)
|
|
{
|
|
$time = $end_time - $begin_time;
|
|
switch ($type) {
|
|
case 'year':
|
|
//总的年
|
|
$timestr = intval($time / 60 / 60 / 24 / 365);
|
|
break;
|
|
case 'month':
|
|
//总的月
|
|
$timestr = intval($time / 60 / 60 / 24 / 30);
|
|
break;
|
|
case 'week':
|
|
$timestr = intval($time / 60 / 60 / 24 / 7);
|
|
break;
|
|
case 'day':
|
|
$timestr = intval($time / 60 / 60 / 24);
|
|
break;
|
|
case 'hour':
|
|
$timestr = intval($time / 60 / 60);
|
|
break;
|
|
case 'min':
|
|
$timestr = intval($time / 60);
|
|
break;
|
|
case 'sec':
|
|
$timestr = $time;
|
|
break;
|
|
default:
|
|
//总的年
|
|
$year = intval($time / 60 / 60 / 24 / 365);
|
|
//总的月
|
|
$month = intval($time / 60 / 60 / 24 / 30);
|
|
//总的周
|
|
$week = intval($time / 60 / 60 / 24 / 7);
|
|
//总的天数
|
|
$day = intval($time / 60 / 60 / 24);
|
|
//总的小时
|
|
$hour = intval($time / 60 / 60);
|
|
//总的分钟数
|
|
$minute = intval($time / 60);
|
|
//总的秒数
|
|
$second = $time;
|
|
$timestr = [
|
|
'year' => $year, //总的年
|
|
'month' => $month, //总的月
|
|
'week' => $week, //总的周
|
|
'day' => $day, //总的天数
|
|
'hour' => $hour, //总的小时
|
|
'min' => $minute, //总的分钟数
|
|
'sec' => $second //总的秒数
|
|
];
|
|
break;
|
|
}
|
|
return $timestr;
|
|
}
|
|
|
|
//获取汉子的首字母
|
|
function getstrcharter($str)
|
|
{
|
|
global $_M, $_YW;
|
|
if (empty($str)) return '';
|
|
$fchar = ord($str{0});
|
|
if ($fchar >= ord('A') && $fchar <= ord('z')) return strtoupper($str{0});
|
|
$s1 = iconv('UTF-8', 'gb2312', $str);
|
|
$s2 = iconv('gb2312', 'UTF-8', $s1);
|
|
$s = $s2 == $str ? $s1 : $str;
|
|
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
|
|
if ($asc >= -20319 && $asc <= -20284) return 'A';
|
|
if ($asc >= -20283 && $asc <= -19776) return 'B';
|
|
if ($asc >= -19775 && $asc <= -19219) return 'C';
|
|
if ($asc >= -19218 && $asc <= -18711) return 'D';
|
|
if ($asc >= -18710 && $asc <= -18527) return 'E';
|
|
if ($asc >= -18526 && $asc <= -18240) return 'F';
|
|
if ($asc >= -18239 && $asc <= -17923) return 'G';
|
|
if ($asc >= -17922 && $asc <= -17418) return 'H';
|
|
if ($asc >= -17417 && $asc <= -16475) return 'J';
|
|
if ($asc >= -16474 && $asc <= -16213) return 'K';
|
|
if ($asc >= -16212 && $asc <= -15641) return 'L';
|
|
if ($asc >= -15640 && $asc <= -15166) return 'M';
|
|
if ($asc >= -15165 && $asc <= -14923) return 'N';
|
|
if ($asc >= -14922 && $asc <= -14915) return 'O';
|
|
if ($asc >= -14914 && $asc <= -14631) return 'P';
|
|
if ($asc >= -14630 && $asc <= -14150) return 'Q';
|
|
if ($asc >= -14149 && $asc <= -14091) return 'R';
|
|
if ($asc >= -14090 && $asc <= -13319) return 'S';
|
|
if ($asc >= -13318 && $asc <= -12839) return 'T';
|
|
if ($asc >= -12838 && $asc <= -12557) return 'W';
|
|
if ($asc >= -12556 && $asc <= -11848) return 'X';
|
|
if ($asc >= -11847 && $asc <= -11056) return 'Y';
|
|
if ($asc >= -11055 && $asc <= -10247) return 'Z';
|
|
return 'ZZ';
|
|
} |