idevlab / helpers
1.0.2
2022-10-30 20:33 UTC
This package is auto-updated.
Last update: 2024-09-29 06:08:48 UTC
README
在我的项目中使用的许多PHP函数,您也可以在您的开发中使用。
作者
安装
使用composer在您的项目中安装。
composer require Idevlab/Helpers
方法
ArrayHelper
::merge(array...$arrays): array
合并数组
/** @var array $foo */
$foo = ['one' => 1, 'three' => 3];
/** @var array $bar */
$bar = ['two' => 2];
$foo = ArrayHelper::merge($foo, $bar); // ['one' => 1, 'three' => 3, 'two' => 2]}
StringHelper
::toSnakeCase(string $string): string
将字符串格式化为snake_case。
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = StringHelper::toSnakeCase($foo); // test_de_chaine
::toPascalCase(string $string): string
将字符串格式化为PascalCase。
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = StringHelper::toPascalCase($foo); // TestDeChaine
::toSkewerCase(string $string): string
将字符串格式化为skewer-case。
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = StringHelper::toSkewerCase($foo); // test-de-chaine
::toNoCase(string $string): string
将字符串格式化为无大小写。
/** @var string $foo */
$foo = 'Test_DeChaine';
$foo = StringHelper::toNoCase($foo); // test de chaine
::toCase(string $string): string
将字符串格式化为无大小写。
/** @var string $foo */
$foo = 'Test_DeChaine';
// NO : 0
// PASCAL : 1
// CAMEL : 2
// SKEWER : 3
// SNAKE : 4
$foo = StringHelper::toCase($foo,1); // test de chaine
JsonHelper
::jsonSerialize(object $object, string ...$excludes): array
序列化对象。
class Foo {
public string $bar = 'purple';
public string $other = 'exclude value';
}
$foo = new Foo();
$foo = JsonHelper::jsonSerialize($foo,['other']); // { 'bar' => 'purple' }
DateHelper
::randomDateForRange(DateTime $start, ?DateTime $end = new DateTime('now')): DateTime
在$start和$end之间查找随机日期