You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
<?php
|
|
|
|
if (!function_exists('generate_tree')) {
|
|
function generate_tree(
|
|
array $flatArray,
|
|
int $parentId = 0,
|
|
array $existsArr = []
|
|
): array {
|
|
$tree = [];
|
|
foreach ($flatArray as $item) {
|
|
if ($item['parent_id'] === $parentId) {
|
|
$node = $item;
|
|
if ($existsArr) {
|
|
$node['is_show'] = in_array($item['id'], $existsArr) ? 1
|
|
: 0;
|
|
}
|
|
$node['children'] = generate_tree(
|
|
$flatArray,
|
|
$item['id'],
|
|
$existsArr
|
|
);
|
|
$tree[] = $node;
|
|
}
|
|
}
|
|
return $tree;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_datetime')) {
|
|
function get_datetime(string $type = 'datetime', int $times = 0): string
|
|
{
|
|
if (!$times) {
|
|
$times = time();
|
|
}
|
|
$format = match ($type) {
|
|
'date' => 'Y-m-d',
|
|
'datetime' => 'Y-m-d H:i:s',
|
|
};
|
|
return date($format, $times);
|
|
}
|
|
}
|
|
|