This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 编码 | |
*/ | |
function userTextEncode($str){ | |
if(!is_string($str))return $str; | |
if(!$str || $str=='undefined')return ''; | |
$text = json_encode($str); //暴露出unicode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 创建树形结构 | |
* @param [type] $data [description] | |
* @param [type] $parent_id [description] | |
* @return [type] [description] | |
*/ | |
public function getTree($data,$parent_id){ | |
$result= array();//结果数组 | |
$len = 0; | |
for($i=0;$i<count($data);$i++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func main() { | |
//返回10个斐波那契数列,todo 使用int,结果数字会越界 | |
fibonacciIndex(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 图片编码 | |
* @param string $img | |
* @param bool $imgHtmlCode | |
* @return string | |
*/ | |
function imgBase64Encode($img = '', $imgHtmlCode = true) | |
{ | |
//如果是本地文件 | |
if(strpos($img,'http') === false && !file_exists($img)){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取指定月份列表时间 | |
* @param $year int 哪年 | |
* @param $start_month int 起止月份 | |
* @param $end_month int 截止月份 | |
* @return array | |
*/ | |
protected function getMonths($year, $start_month, $end_month) | |
{ | |
$month = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bin_sch($array, $low, $high, $k){ | |
if ($low <= $high){ | |
$mid = intval(($low+$high)/2); | |
if ($array[$mid] == $k){ | |
return $mid; | |
}elseif ($k < $array[$mid]){ | |
return bin_sch($array, $low, $mid-1, $k); | |
}else{ | |
return bin_sch($array, $mid+1, $high, $k); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findSmall($arr){ | |
$small = $arr[0]; | |
$small_index = 0; | |
for ($i=0; $i < count($arr); $i++) { | |
if($arr[$i] < $small){ | |
$small_index = $i; | |
$small = $arr[$i]; | |
} | |
} | |
return $small_index; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function quickSort($array) | |
{ | |
if(!isset($array[1])) return $array; | |
$base = $array[0]; //获取一个用于分割的关键字,一般是首个元素 | |
$leftArray = []; | |
$rightArray = []; | |
for($i=1; $i<count($array); $i++) | |
{ | |
if($array[$i] > $base) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 冒泡排序算法 | |
* @param array $arr | |
* @return array | |
*/ | |
function bubble_sort($arr) { | |
// 判断参数是否为数组,且不为空 | |
if (!is_array($arr) || empty($arr)) { | |
return $arr; | |
} |
NewerOlder