[php]PHP_函数收集
//http://php.net/manual/en/control-structures.break.php
//break ends execution of the current for, foreach, while, do-while or switch structure.
//break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of. The default value is 1, only the immediate enclosing structure is broken out of.
//
// Function1 : 生成随机字符串
private function _generateCode($ref_list)
{
do{
$str_num = str_replace(array("o" , "i" , "l" , "z" , "0" , "1" , "2") , "" , md5(strtotime('now'))); $str_num = substr($str_num , 0 , 4);
}while(isset($ref_list[$str_num])); return $str_num;
}
// Function2 : 对数组中的数据排序(usort($arr_questionInfo , array($this , 'cmp'));)
private function cmp($a , $b)
{
$aLevel = ceil($a['match_rate'] * 100);
$bLevel = ceil($b['match_rate'] * 100); if($aLevel == $bLevel)
{
if($a['score'] == $b['score'])
{
return 0;
} else if($a['score'] > $b['score']) {
return -1;
} else {
return 1;
}
} else if ($aLevel > $bLevel)
{
return -1;
} else {
return 1;
}
}
// Function 3: 两个数组的比较
private function _formatIndex($arr_tableIndex , $str_index)
{
$arr_unformatedIndex = explode(INDEX_COMBINE_SEPERATE , $str_index);
$str_formatedIndex = false;
foreach($arr_tableIndex as $value)
{
$arr_tableIndex = explode(INDEX_COMBINE_SEPERATE , $value);
//找到对应的索引的名了,直接退出
if(empty(array_diff($arr_unformatedIndex , $arr_tableIndex)) &&
empty(array_diff($arr_tableIndex , $arr_unformatedIndex)))
{
$str_formatedIndex = $value;
break;
}
}
return $str_formatedIndex;
}
// Funtion 4 : 通过引用直接在遍历数组的过程中改变数组的值 public static function formatValue(&$arr_value)
{ foreach($arr_value as &$value)
{
if(is_array($value))
{
$value = implode("," , $value);
}
}
}
/*
* @desc 生成远程的唯一ID。ID一共8个字节,
* 1字节:用于类型前缀
5字节: 用于时间
3字节: 用于自增
* @param
* $redisLink redis连接
* $type ID的类型
* $key 主键值
*/
static function createRemotID($redisLink , $type , $key)
{
$idPrefix = $type << 56;
$maxNum = 2 << 20;
do{
$idNum = $redisLink->incr($key);
if($idNum >= $maxNum)
{
$redisLink->set($key , 0);
}
} while($idNum >= $maxNum); $time = ceil(microtime(true) * 1000) << 24;
$id = $idPrefix + $time + $idNum;
$id .= "";
return $id;
}
[php]PHP_函数收集的更多相关文章
- Javascript常用方法函数收集(二)
Javascript常用方法函数收集(二) 31.判断是否Touch屏幕 function isTouchScreen(){ return (('ontouchstart' in window) || ...
- js函数收集
常见js函数收集: 转自:http://www.qdfuns.com/notes/36030/2eb2d45cccd4e62020b0a6f0586390af.html //运动框架 function ...
- day09-Python运维开发基础(函数收集参数、命名关键字参数与返回值、函数名的特殊使用及 全局/局部变量详解)
1. 函数收集参数.命名关键字参数与返回值.函数名的特殊使用 # ### 默认形参 和 关键字实参 # 默认形参和 关键字实参 在写法上是一样 # 函数的定义处 """默 ...
- javascript常用方法函数收集
收集了一些比较常用的javascript函数. 1.字符串长度截取 function cutstr(str, len) { var temp, icount = 0, patrn = /[^\x00- ...
- python函数收集不确定数量的值
python写函数的时候,有时候会不确定到底传入多少值. 首先是,*args,单星号参数收集参数: 1 #!usr/bin/python 2 #-*-coding:utf-8-*- 3 4 #定义一个 ...
- 实用js函数收集
1. 全选复选框: //复选框全选函数 function SelectAll() { var checkAll = document.getElementsByName("checkAll& ...
- js常用函数收集
在js中,可以使用typeof获取变量或函数的类型,如下: <head runat="server"> <title></title> < ...
- Python3基础 函数 收集参数+普通参数 的示例
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- iOS 中基础字符判断函数收集(如判断大小写、数字等)
函数:isdigit 用法:#include 功能:判断字符c是否为数字 说明:当c为数字0-9时,返回非零值,否则返回零. 函数:islower 用法:#include 功能:判断字符c是否为小写英 ...
随机推荐
- svn冲突问题解决办法
经常有人会说,树冲突是很难解决的一类冲突,其实一旦了解了其原理,要解决也不难.先回顾下对于树冲突的定义. 树冲突:当一名开发人员移动.重命名.删除一个文件或文件夹,而另一名开发人员也对它们进行 ...
- BZOJ 1791: [IOI2008]Island 岛屿 - 基环树
传送门 题解 题意 = 找出无向基环树森林的每颗基环树的直径. 我们首先需要找到每颗基环树的环, 但是因为是无向图,用tarjan找环, 加个手工栈, 我也是看了dalao的博客才知道tarjan找无 ...
- kafka配置简要描述
配置文件在config/server.properties 下面的一些配置可能是你需要进行修改的. 这里为官方提供配置文件解释:https://kafka.apache.org/08/configur ...
- start()方法和run()方法有什么区别?
通过调用线程类的start()方法来启动一个线程,使线程处于就绪状态,即可以被JVM来调度执行,在调度过程中,JVM通过调用线程类的run()方法来完成实际的业务逻辑,当run()方法结束后,此线程就 ...
- Spring 注解(二)注解工具类 AnnotationUtils 和 AnnotatedElementUtils
Spring 注解(二)注解工具类 AnnotationUtils 和 AnnotatedElementUtils Spring 系列目录(https://www.cnblogs.com/binary ...
- PHP 过滤特殊符号
function strFilter($str){ $str = str_replace('`', '', $str); $str = str_replace('·', '', $str); $str ...
- python 日志滚动 分文件
import logging from logging.handlers import RotatingFileHandler import datetime import os def main() ...
- 设计模式之生成者模式java源代码
假设要组装一辆自行车,并且自行车就是车轮和车架组成. Builder对应于组装自行车所使用的车轮和车架 ConcreteBuiler对应于自行车的车轮和车架,同时可以返回一辆自行车. Product对 ...
- 基于tomcat的solr环境搭建(Linux)
♥♥ solr是基于lucene的一个全文检索服务器,提供了一些类似webservice的API接口,用户可以通过http请求solr服务器,进行索引的建立和索引的搜索.索引建立的过程:用户提交的文 ...
- Flex的Number和Text
今天要说的问题不是Number和String转换的问题.而是使用时容易出的一些错误: public static function ToFixed(value:Number, digits:uint ...