
php
番茄蛋饭25块半
这个作者很懒,什么都没留下…
展开
-
树与二维数组的相互转换
树的转换原创 2022-06-14 13:49:54 · 527 阅读 · 0 评论 -
jenssegers/mongodb 的elemmatch一些使用方法
中文文档://等值数组查询where('domain', 'elemmatch',['selfbuild_brand_id'=> $date['selfbuild_brand_id']])//数组模糊查询 用正则表达式实现use MongoDB\BSON\Regex;where('domain', 'elemmatch',[ 'mx_brand_name'=>new Regex('.*'.$date['mx'].'.*', 'i')]);//数组其他表达式原创 2022-02-28 15:49:42 · 664 阅读 · 0 评论 -
PHP7版本以上请用Throwable 捕捉异常和错误
之前一直用exception 捕捉异常后来发现一次异常捕捉不到了(其实是错误)7以上exception与error是分开的Throwable does not work on PHP 5.x.To catch both exceptions and errors in PHP 5.x and 7, add a catch block for Exception AFTER catching Throwable first.Once PHP 5.x support is no longer原创 2022-01-27 14:15:21 · 585 阅读 · 0 评论 -
Laravel json 数组查询
简单查询// 例如字段filed内容 {"time":"2012-12-01"}where("filed->time","2012-12-01")数组查询// 字段field 内容[{"time":"2012-12-01"}]->whereJsonContains("field ",["time"=>"2022-02-27 12:12:12"])//或者->whereRaw("json_contains(`field `, json_object('time'原创 2022-01-14 21:30:40 · 2008 阅读 · 0 评论 -
laravel 实现分组前几名
$sql = UserRelationMap::select('inviter_id','business_id', DB::raw('COUNT(id) as num,any_value(id) as id,any_value(project_id) as project_id,any_value(employee_id) as employee_id'), DB::raw('ROW_NUMBER() OVER (PARTITION BY busine...原创 2022-01-12 16:44:15 · 488 阅读 · 0 评论 -
Laravel 如何 groupBy 之后进行Order 排序
//先group分组 $sql = BlindBox::selectRaw('any_value(id) as id, any_value(business_id) as business_id,project_id,SUM(access_count) as access_count,SUM(join_count) as join_count,SUM(share_count) as share_count')->groupBy('project_id');//然后from 查询排序 $lis.原创 2022-01-11 17:16:09 · 1068 阅读 · 0 评论 -
PHP 一维数组字符串转整型数字
很多接口我们会遇到["6","10"] 这样的字符串数组,可是我们需要的是[6,10]这里推荐一种不用循环解决的方案:$str = ["6","10"];$str = json_decode('[' . $str. ']', true);//[6,10]原创 2021-10-18 16:44:00 · 598 阅读 · 1 评论 -
PHP引用实现树状数组
$refer = [];//临时数组 $tree = [];//树状结构 $list = [];//二维带level foreach ($data as $key => $value) { $refer[$value['id']] = &$data[$key]; } foreach ($data as $k => $v) { if ($v['p...原创 2021-09-24 17:35:27 · 215 阅读 · 0 评论 -
Passport个人访问令牌指定客户端ID
在passport v10以上已经移除了相关设置接口,我们可以重写createToken方法实现指定客户端ID public function createToken($name, array $scopes = []) { $clients = new ClientRepository('9466f475-de2d-47fc-9f14-ec8c1fed7f8d'); $pr = Container::getInstance()->make(Pers原创 2021-09-22 10:42:00 · 194 阅读 · 0 评论 -
非递归实现无限极分类
public static function ListToTree($list, $primaryKey='id', $parentKey = 'up_id', $childStr = 'children', $root = 0) { $tree = array(); if (is_array($list)) { //创建基于主键的数组引用 $refer = array(); for...原创 2021-05-21 15:48:10 · 175 阅读 · 0 评论 -
git 拉取提示本地文件修改错误,其实并没有修改
有时遇到本地文件明明没修改,pull提示文件修改的错误error: Your local changes to the following files would be overwritten by merge:Please commit your changes or stash them before you merge.这种情况可能是文件权限变更引起的,gitconfigcore.filemodefalse或者用另一个思路,把文件rm 再restore回来即可...原创 2021-05-06 16:42:19 · 828 阅读 · 0 评论 -
Laravel水平分表及对应查询
余数一定小于除数,用10作为除数可以把user表拆分成user0.......user9根据id 可以确定用户存在哪个表中查询所有数据 for ($i = 0; $i < 10; $i++) { $queries->push(DB::table('user_operator_record' . $i) ->where([ ['act原创 2021-04-26 14:47:55 · 655 阅读 · 0 评论 -
curl 获得结果有头部信息
curl 有时返回结果会含有头部信息需要处理$curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTT原创 2021-01-25 15:49:54 · 709 阅读 · 0 评论