+ add zin and zui3 files.

This commit is contained in:
sunhao
2023-07-25 17:42:27 +08:00
parent b92acecc1a
commit e97ab9686b
234 changed files with 82310 additions and 178 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace zin\utils;
function deepGet(object|array &$data, string $namePath, mixed $defaultValue = null): mixed
{
$names = explode('.', $namePath);
foreach($names as $name)
{
if(is_object($data))
{
if(!isset($data->$name)) return $defaultValue;
$data = &$data->$name;
continue;
}
if(!is_array($data) || !isset($data[$name])) return $defaultValue;
$data = &$data[$name];
}
return $data === null ? $defaultValue : $data;
}
function deepSet(array &$data, string $namePath, mixed $value)
{
$names = explode('.', $namePath);
$lastName = array_pop($names);
if(!empty($names))
{
foreach($names as $name)
{
if(!is_array($data)) return;
if(!isset($data[$name])) $data[$name] = array();
$data = &$data[$name];
}
}
$data[$lastName] = $value;
}