shiroi blog

This is my blog...

开启Chrome自带的多线程下载功能

  1. 打开 Chrome 浏览器,国产 Chrome 内核的浏览器通通适用,包括前段时间推送的新版 Edge 也可以
  2. 在地址栏输入 chrome://flags/#enable-parallel-downloading
  3. 打开后如下图模式
    201911201574231257754319.jpg
  4. 选择“Enable”,出现"Relaunch"(重启浏览器),点击它
  5. 重启后就开启了多线程下载功能,接下来咱们再来看看之前文件的下载速度。
  6. 201911201574231315160445.gif

laravel获取路由的两种方式

$routes = app()->router->getRoutes();
//第一种
foreach ($routes as $k => $value) {
    if($value->action['namespace'] == 'App\Http\Controllers\Api') {
        $path[$k]['uri'] = $value->uri;
        $path[$k]['path'] = $value->methods[0];
    }
}
dump($path);

//第二种
$data = [];
$routes = collect($routes)->map(function ($route) use ($data) {
    if($route->action['namespace'] == 'App\Http\Controllers\Api') {
        $data['uri'] = $route->uri;
        $data['path'] = $route->methods[0];
    }
    return $data;
})->filter()->all();
dump($routes);

根据分类实现无限级

数组

$array = [
    [
        "username"=>"xiaxian2",
        "headimg"=>"/Templates/home/res/face/3.png",
        "money"=>"99500.00",
        "yongjin"=>"0.00",
        "yongjingai"=>"0",
        "jiesuan"=>"0.00",
        "agent"=>"8e5d35bf1414296e03c7846ebab7af6e",
        "userid"=>"09b42ce90879719a67f050b431b03534",
        "zongliushui"=>"500",
        "zongyinkui"=>null
    ],
    [
        "username"=>"erjixiaxian2",
        "headimg"=>"/Templates/home/res/face/3.png",
        "money"=>"99400.00",
        "yongjin"=>"0.00",
        "yongjingai"=>"0",
        "jiesuan"=>"0.00",
        "agent"=>"e89c3cb72cc95e2e7014d3d07b97beb2",
        "userid"=>"2a1ab4890db2142c6c0bb51ef77994fb",
        "zongliushui"=>"600",
        "zongyinkui"=>null
    ],
    [
        "username"=>"erjixiaxian",
        "headimg"=>"/Templates/home/res/face/3.png",
        "money"=>"100592.80",
        "yongjin"=>"0.00",
        "yongjingai"=>"0",
        "jiesuan"=>"0.00",
        "agent"=>"e89c3cb72cc95e2e7014d3d07b97beb2",
        "userid"=>"6256d265dcc1e9cfca2c37c1093444cb",
        "zongliushui"=>"600",
        "zongyinkui"=>"592.8"
    ],
    [
        "username"=>"admin",
        "headimg"=>"/Templates/home/res/face/2.png",
        "money"=>"11038.83",
        "yongjin"=>"1.50",
        "yongjingai"=>"1",
        "jiesuan"=>"7.50",
        "agent"=>"7d9e993765d4f79748ec54cbed9a996e",
        "userid"=>"8e5d35bf1414296e03c7846ebab7af6e",
        "zongliushui"=>"5821",
        "zongyinkui"=>"8351.548"
    ],
    [
        "username"=>"xiaxian1",
        "headimg"=>"/Templates/home/res/face/3.png",
        "money"=>"97494.00",
        "yongjin"=>"0.00",
        "yongjingai"=>"0",
        "jiesuan"=>"0.00",
        "agent"=>"8e5d35bf1414296e03c7846ebab7af6e",
        "userid"=>"e89c3cb72cc95e2e7014d3d07b97beb2",
        "zongliushui"=>"3500",
        "zongyinkui"=>"-2006"
    ]
];

引用算法

//引用算法
function generateTree($array){
    //第一步 构造数据
    $items = array();
    foreach($array as $value){
        $items[$value['userid']] = $value;
    }
    //第二部 遍历数据 生成树状结构
    $tree = array();
    foreach($items as $key => $value){
        if(isset($items[$value['agent']])){
            $items[$value['agent']]['son'][] = &$items[$key];
        }else{
            $tree[] = &$items[$key];
        }
    }
    return $tree;
}

$a = generateTree($array);
dd($a);

结果

[
    {
        "username": "admin",
        "headimg": "/Templates/home/res/face/2.png",
        "money": "11038.83",
        "yongjin": "1.50",
        "yongjingai": "1",
        "jiesuan": "7.50",
        "agent": "7d9e993765d4f79748ec54cbed9a996e",
        "userid": "8e5d35bf1414296e03c7846ebab7af6e",
        "zongliushui": "5821",
        "zongyinkui": "8351.548",
        "son": [
            {
                "username": "xiaxian2",
                "headimg": "/Templates/home/res/face/3.png",
                "money": "99500.00",
                "yongjin": "0.00",
                "yongjingai": "0",
                "jiesuan": "0.00",
                "agent": "8e5d35bf1414296e03c7846ebab7af6e",
                "userid": "09b42ce90879719a67f050b431b03534",
                "zongliushui": "500",
                "zongyinkui": null
            },
            {
                "username": "xiaxian1",
                "headimg": "/Templates/home/res/face/3.png",
                "money": "97494.00",
                "yongjin": "0.00",
                "yongjingai": "0",
                "jiesuan": "0.00",
                "agent": "8e5d35bf1414296e03c7846ebab7af6e",
                "userid": "e89c3cb72cc95e2e7014d3d07b97beb2",
                "zongliushui": "3500",
                "zongyinkui": "-2006",
                "son": [
                    Array(),
                    Array()
                ]
            }
        ]
    }
]

阅读

mysql 数据库关联多张表

表一:

CREATE TABLE `log_zz` (
  `dt` datetime NOT NULL,
  `info` varchar(100) NOT NULL,
  KEY `dt` (`dt`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

表二:

CREATE TABLE `log_xx` (
  `dt` datetime NOT NULL,
  `info` varchar(100) NOT NULL,
  KEY `dt` (`dt`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

表三:

CREATE TABLE `log_yy` (
  `dt` datetime NOT NULL,
  `info` varchar(100) NOT NULL,
  KEY `dt` (`dt`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

关联表:

CREATE TABLE `log_merge` (
  `dt` datetime NOT NULL,
  `info` varchar(100) NOT NULL,
  KEY `dt` (`dt`)
) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 UNION=(`log_zz`,`log_xx`,`log_yy`);

这是三张表的数据:
D5Q7}IL{10TRQGAF@47D~61.png

这是关联表的数据:

关联表数据

执行代码

查询:select * from log_merge;
删除:delete from log_merge where `dt`='2020-08-10 10:48:53';
更新:update table where  `dt`='2020-08-10 10:48:53' set `info` = 'SS';

composer的自动加载机制

composer支持四种模式(psr0,psr4,classmap,files)

composer默认psr4,支持php5.2
PSR-4指定的就当作当前命名空间的目录, 而PSR-0 指定的是当前命名空间的父目录。composer dump-autoload 一下

<?php
//实现自动加载类
spl_autoload_register(function ($class) {
    /* 限定类名路径映射 */
    $class_map = array(
        // 限定类名 => 文件路径
        $class => $class.".php",
    );
    /* 引入相关文件 */
    if (file_exists($file = $class_map[$class])) include $file;
});
//按照顺序加载(按照命名空间寻找)
$aa =new \classes\AA();
$aa->aa();
echo "\n";
$bb = new \classes\BB();
$bb->bb();
echo "\n";
$sasasaasds = new \saadsadsas\sasasaasds();
$sasasaasds->wqwqwq();
echo "\n";
$fwqdqwd = new \wqeqweqw\fwqdqwd();
$fwqdqwd->尼玛();

sql_autoload_register() 函数 跟 __autoload()相比,
1.__autoload($class) 因为是一个函数,所以只能定义一次,使用多个会冲突报错;而 sql_autoload_register('function') 可定义多个,它有效地创建一个队列的自动装载函数并按顺序依次定义

2.SPL函数很丰富,有更多的操作空间:如spl_autoload_unregister()注销已经注册的函数、spl_autoload_functions()返回所有已经注册的函数等

备案号:粤ICP备18155514号-2