[php]PHP_函数收集
2016-01-05 16:23
435 查看
//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.
//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函数内访问全局变量
- 如何将editplus设置为不自动备份我的文件
- php5 php7 变量区别
- PHP分页类
- PHP使用Pear发送邮件(Windows环境)
- WordPress中用于获取搜索表单的PHP函数使用解析
- (转)PHP中文处理 中文字符串截取(mb_substr)和获取中文字符串字数
- [PHP] php中常见小问题汇总
- phpcms V9 内容模型管理
- PHP验证码
- Windows IIS6.1 配置PHP7.0.1
- php 函数参数引用和普通变量 传参区别
- PHP5.4安装xhprof扩展[不要去pecl下载]
- PHP判断访问用户是使用PC浏览器和手机浏览器
- [PHP] 常用php函数汇总
- 利用matplotlib中imshow()函数绘图
- php视频直播
- Swoole:重新定义PHP
- VSFTPD全攻略(/etc/vsftpd/vsftpd.conf文件详解)
- PhpStorm 设置php代码格式