| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- // 应用公共文件
- /**
- * @param bool $bool
- * @param $message
- * @param int $code
- * @throws \app\exception\BaseException
- */
- function predicate(bool $bool, $message, $code = 1012) {
- if (!$bool) {
- throw new \app\exception\BaseException($message, $code);
- }
- }
- /**
- * 格式化字符串
- * @param $value
- * @param null $def
- * @return null
- */
- function format_string($value, $def = null) {
- return $value != null && strlen(strval($value)) > 0 ? $value : $def;
- }
- /**
- * @param $array
- * @param $id
- * @return array 树状Menu
- */
- function recursion($array, $id = 0)
- {
- $resArray = [];
- foreach ($array as $key => $value)
- {
- if ($value['pid'] == $id)
- {
- $resArray[$key] = $array[$key];
- $resArray[$key]['children'] = recursion($array, $value['id']);
- }
- }
- return array_merge($resArray);
- }
|