2 Star 1 Fork 1

leoleo/php函数通用和链接

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
function.php 2.25 KB
一键复制 编辑 原始数据 按行查看 历史
leoleo 提交于 2021-06-04 16:56 . update function.php.
<?php
// 父子类
function treeLevel(array $data, int $pid = 0, string $html = '--', int $level = 0)
{
static $arr = [];
foreach ($data as $val) {
if ($pid == $val['pid']) {
// 重复一个字符多少次
$val['html'] = str_repeat($html, $level * 2);
$val['level'] = $level + 1;
$arr[] = $val;
$this->treeLevel($data, $val['id'], $html, $val['level']);
}
}
return $arr;
}
// 树状多层级
function subTree(array $data, int $pid = 0)
{
$arr = [];
foreach ($data as $val) {
if ($pid == $val['pid']) {
$val['sub'] = $this->subTree($data, $val['id']);
$arr[] = $val;
}
}
return $arr;
}
// 树状多层级优化版
function subTree(array $data,string $key = 'unid',string $child = 'child',$parent = '',$pid = 0){
$arr = [];
foreach ($data as $val) {
if ($pid == $val[$parent]) {
$val[$child] = subTree($data, $key,$child,$parent,$val[$key]);
$arr[] = $val;
}
}
return $arr;
}
// 引用解决树状多层级
public function getTree(array $data,string $key='id',string $child = 'children',string $parent = '',$pid = 0){
$array = [];
foreach($data as $value){
$array[$value[$key]] = $value;
}
foreach($array as $k=>$v){
if(isset($array[$v[$parent]])){
$array[$v[$parent]][$child][] = &$array[$k];
}else{
$reback[] = &$array[$k];
}
}
return $reback;
}
//毫秒级时间戳
function getMillisecond() {
list($t1, $t2) = explode(' ', microtime());
return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
}
// mysql批量更新 相当与 id = 1 时 inventory = 1 id = 2时 inventory = 2 $update_unid 需要更新的主键
UPDATE pro_goods_spec_price
SET inventory = CASE unid
//这是占位符 格式是 WHEN 1 THEN 1 WHEN 2 THEN 2
%s
END,
SET sales = CASE unid
%s
END
WHERE unid IN $update_unid
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/huiohuio/infinite_recursive_function.git
git@gitee.com:huiohuio/infinite_recursive_function.git
huiohuio
infinite_recursive_function
php函数通用和链接
master

搜索帮助