123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- use Hashids\Hashids;
- /**
- * Here is your custom functions.
- */
- /*
- 快速排序
- */
- function quickSort($array)
- {
- if(!isset($array[1]))
- return $array;
- $mid = $array[0]; //获取一个用于分割的关键字,一般是首个元素
- $leftArray = array();
- $rightArray = array();
- foreach($array as $v)
- {
- if($v > $mid)
- $rightArray[] = $v; //把比$mid大的数放到一个数组里
- if($v < $mid)
- $leftArray[] = $v; //把比$mid小的数放到另一个数组里
- }
- $leftArray = quickSort($leftArray); //把比较小的数组再一次进行分割
- $leftArray[] = $mid; //把分割的元素加到小的数组后面,不能忘了它哦
- $rightArray = quickSort($rightArray); //把比较大的数组再一次进行分割
- return array_merge($leftArray,$rightArray); //组合两个结果
- }
- // 获取Hashids 对象
- function getHashids(){
- global $hashids;
- if($hashids instanceof Hashids ){
- return $hashids;
- }
- $hashids = new Hashids('D6M97LIvpp4qWuz3nKzqi6yYN4GAA61b',32);
- return $hashids;
-
- }
- /**
- * 获取对象或数组的属性值
- * @param $param
- * @param $key
- * @param string $default
- * @return mixed|string
- */
- function getProp($param, $key, $default = '')
- {
- $result = $default;
- if (is_object($param) && isset($param->$key)) {
- $result = $param->$key;
- }
- if (is_array($param) && isset($param[$key])) {
- $result = $param[$key];
- }
- return $result;
- }
- /**
- * 获取真实IP
- */
- function get_client_ip($type = 0, $adv = true)
- {
- $type = $type ? 1 : 0;
- if ($adv) {
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- $pos = array_search('unknown', $arr);
- if (false !== $pos) {
- unset($arr[$pos]);
- }
- $ip = trim($arr[0]);
- } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- // IP地址合法验证
- $long = sprintf("%u", ip2long($ip));
- $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
- return $ip[$type];
- }
- /**
- * 获取真实IP
- */
- function get_client_ua()
- {
- $ua = $_SERVER['HTTP_USER_AGENT'];
- return $ua;
- }
|