Skip to content

Commit d554a0a

Browse files
committed
增加array_is_list json_validate助手函数
1 parent c7c4edc commit d554a0a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/helper.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,30 @@ function class_uses_recursive($class): array
288288
return array_unique($results);
289289
}
290290
}
291+
292+
if (!function_exists('array_is_list')) {
293+
/**
294+
* 判断数组是否为list
295+
*
296+
* @param array $array 数据
297+
* @return bool
298+
*/
299+
function array_is_list(array $array): bool
300+
{
301+
return array_values($array) === $array;
302+
}
303+
}
304+
305+
if (!function_exists('json_validate')) {
306+
/**
307+
* 判断是否为有效json数据
308+
*
309+
* @param string $string 数据
310+
* @return bool
311+
*/
312+
function json_validate(string $string): bool
313+
{
314+
json_decode($string);
315+
return json_last_error() === JSON_ERROR_NONE;
316+
}
317+
}

0 commit comments

Comments
 (0)