idevlab / essential
所有对idevlab项目开发有用的方法和工具。
1.8.0
2022-10-31 08:50 UTC
Requires
- php: ^8.1
- ext-mbstring: *
- idevlab/helpers: ^1.0
This package is auto-updated.
Last update: 2024-09-29 06:14:57 UTC
README
在项目中使用的许多PHP函数,您可以在自己的开发中使用。
作者
安装
使用composer在您的项目中安装。
composer require idevlab/essential
方法
数组
i_array_merge(array...$arrays): array
合并数组
/** @var array $foo */
$foo = ['one' => 1, 'three' => 3];
/** @var array $bar */
$bar = ['two' => 2];
$foo = i_array_merge($foo, $bar); // ['one' => 1, 'three' => 3, 'two' => 2]}
字符串
str_to_snake_case(string $string): string
将字符串格式化为snake_case。
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = str_to_snake_case($foo); // test_de_chaine
str_to_pascal_case(string $string): string
将字符串格式化为PascalCase。
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = str_to_pascal_case($foo); // TestDeChaine
str_to_skewer_case(string $string): string
将字符串格式化为skewer-case。
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = str_to_skewer_case($foo); // test-de-chaine
str_to_no_case(string $string): string
将字符串格式化为无大小写。
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = str_to_no_case($foo); // test de chaine
str_to_case(string $string): string
将字符串格式化为无大小写。
/** @var string $foo */
$foo = 'Test_DeChaine';
// NO : 0
// PASCAL : 1
// CAMEL : 2
// SKEWER : 3
// SNAKE : 4
$foo = str_to_case($foo,1); // test de chaine
JSON
i_json_serialize(object $object, string ...$excludes): array
序列化对象。
class Foo {
public string $bar = 'purple';
public string $other = 'exclude value';
}
$foo = new Foo();
$foo = i_json_serialize($foo,['other']); // { 'bar' => 'purple' }
日期
i_random_date(DateTime $start, ?DateTime $end = new DateTime('now')): DateTime
在 $start 和 $end 之间查找随机日期