栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

PHP实用函数集合

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP实用函数集合

推荐:《PHP视频教程》

实用函数集合

= 10) {
      $nx = 1 + ($ix % 10);
      $total += $nx;
  } else {
      $total += $ix;
  }
     } else {
  $total += $n;
     }
     $i++;
 }
 $total -= $last_n;
 $total *= 9;

 return $last_n == ($total % 10);
    }
}

if (!function_exists('blocking_lock')) {
    
    function blocking_lock(string $lock_name, $valid = 3600)
    {
 $lock_key = 'blocking_lock';
 while ($exp = Redis::hget($lock_key, $lock_name)) {
     if ($exp < microtime(true)) {
  Redis::hdel($lock_key, $lock_name);
     }
     usleep(10);
 }

 return Redis::hset($lock_key, $lock_name, microtime(true) + $valid);
    }
}

if (!function_exists('blocking_unlock')) {
    
    function blocking_unlock(string $lock_name)
    {
 $lock_key = 'blocking_lock';

 return Redis::hdel($lock_key, $lock_name);
    }
}

if (!function_exists('random_color')) {
    
    function random_color()
    {
 $str = '#';
 for ($i = 0; $i < 6; $i++) {
     $randNum = rand(0, 15);
     switch ($randNum) {
  case 10:
      $randNum = 'a';
      break;
  case 11:
      $randNum = 'b';
      break;
  case 12:
      $randNum = 'c';
      break;
  case 13:
      $randNum = 'd';
      break;
  case 14:
      $randNum = 'e';
      break;
  case 15:
      $randNum = 'f';
      break;
     }
     $str .= $randNum;
 }

 return $str;
    }
}

if (!function_exists('get_hour_history')) {
    
    function get_hour_history()
    {
 $history = [];
 for ($i = 0; $i <= date('H'); $i++) {
     $history[] = $i;
 }

 return $history;
    }
}

以上就是PHP实用函数集合的详细内容,更多请关注考高分网其它相关文章!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/262628.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号