目录
递归类
- 无限上级
function shangji($uid, &$array = []) { $is_parent = Db::name('user')->where('user_id', $uid)->field('father_id')->find(); if ($is_parent["father_id"] != 0) { $array[] = $is_parent['father_id']; $this->shangji($is_parent['father_id'], $array); } return $array; }
- 无限下级
function xiaji($user_id, &$result = []) { $list = Db::name('user')->where('father_user_id', $user_id)->column('id'); if (!empty($list)) { foreach ($list as $key => $val) { $result[] = $val; $this->xiaji($val, $result); } } return $result; }
请求类
- 解决thinkphp6跨域问题:(转载至)https://www.csdn.net/tags/MtTaEgysMDYxODcyLWJsb2cO0O0O.html
https://www.csdn.net/tags/MtTaEgysMDYxODcyLWJsb2cO0O0O.html
- 模拟GET请求
function curl_get($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $output = curl_exec($ch); curl_close($ch); return $output; }
- 模拟POST请求
function curl_post($url, $array) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); $post_data = $array; curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); $data = curl_exec($curl); curl_close($curl); return $data; }
常用函数
function daily_list()
{
round('XXX', 2);//保留N位小数
json_encode($array, JSON_UNESCAPED_UNICODE);//数组转JSON,保留中文
json_decode($JSON, false);//JSON转数组,TRUE为对象
substr("Hello world", 6);//从第六位开始截取字符串,负数为从后面截取
implode(',', $array);//使用逗号分隔数组为字符串
explode(',', $string);//根据逗号将字符串转为数组
array_unique($array);//数组去重
asort($array); //根据关联数组的值,对数组进行升序排列
ksort($array);// 根据关联数组的键,对数组进行升序排列
arsort($array);// 根据关联数组的值,对数组进行降序排列
krsort($array);// 根据关联数组的键,对数组进行降序排列
}
后期不断完善