s-mcdonald / functions

0.3.0 2023-06-06 10:16 UTC

This package is auto-updated.

Last update: 2024-09-06 13:31:08 UTC


README

Source Source

设置。

首先通过composer安装,然后在使用语句中导入函数。例如

use function SamMcDonald\Functions\random_bool;

random_bool

random_bool() ? 'foo' : 'bar';

array_rand_bias

echo array_rand_bias($array);

例如,以下是一组姓名数组;

$myarray = [
    'David',
    'Matthew',
     ...
    'George',
];

从索引开始,姓名有下降趋势,例如David。所以David将被选择最多,然后是Mathew,依此类推,直到最后一个元素。

array_entry_exist

if (array_entry_exist($array, 'foo', 'bar')) {...}

// Which is a more convenient way of typing 
if (isset($array['foo']) && $array['foo'] === 'bar') {}

array_rand_pluck

$randomValue = array_rand_pluck($array);

// Alternative
$randomValue = $array[array_rand($array, 1)];

like_int

$like_int = "55";

if(like_int($like_int)) {
    echo "Yes this is could certainly be cast to an int.", PHP_EOL;
}

slugify

echo slugify("My friends long weekend at Bernie's");

通过composer安装

composer require s-mcdonald/functions

依赖项

  • PHP 8.0

许可协议

Functions遵循MIT许可协议(有关详细信息,请参阅LICENSE文件)。