s-mcdonald/functions

assortment of php functions

0.3.0 2023-06-06 10:16 UTC

This package is auto-updated.

Last update: 2024-04-06 12:33:45 UTC


README

Source Source

Setup.

First install via composer, then import the function in the using statements. eg:

use function SamMcDonald\Functions\random_bool;

random_bool

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

array_rand_bias

echo array_rand_bias($array);

For example, take the following array of names;

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

There is a descending trend in the names from the start of the index such as David. So David will be picked mostly, then Mathew and so on until the last element.

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");

Install via composer

composer require s-mcdonald/functions

Dependencies

  • Php 8.0

License

Functions is licensed under the terms of the MIT License (See LICENSE file for details).