zoukankan      html  css  js  c++  java
  • [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;
    		}
    
  • 相关阅读:
    CF710F String Set Queries AC自动机 二进制分组
    类欧几里得学习笔记
    P2053 [SCOI2007]修车 网络流
    螺旋方阵
    灯的排列问题
    编码问题
    论文阅读博客模板
    论文阅读框架模板
    动作识别论文20191104_Probabilistic selection of frames for early action recognition in videos
    剑指offer 57. 数字序列中某一位的数字
  • 原文地址:https://www.cnblogs.com/shuman/p/5102773.html
Copyright © 2011-2022 走看看