PHP code example of andrey-helldar / helpers

1. Go to this page and download the library: Download andrey-helldar/helpers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andrey-helldar / helpers example snippets


Helldar\Helpers\LaravelServiceProvider::class,

echo array_item_value_max_length(array $array = []) : int

echo (new \Helldar\Helpers\Support\Arr(array $array = []))
    ->arrayItemValueMaxLength() : int

array_add_unique(array &$array, $value)

(new \Helldar\Helpers\Support\Arr())
    ->addUnique(&$array, $value = 'value')

(new \Helldar\Helpers\Support\Arr())
    ->addUnique(&$array, $value = ['value1', 'value2', ...])

return array_rename_keys($callback, array $array = []) : array

return (new \Helldar\Helpers\Support\Arr(array $array = []))
    ->arrayRenameKeys($callback) : array

return array_size_max_value(array $array = []) : int

return (new \Helldar\Helpers\Support\Arr((array $array = []))
    ->arraySizeOfMaxValue() : int

array_sort_by_keys_array($array, $sorter) : void

(new \Helldar\Helpers\Support\Arr())
    ->sortByKeysArray($array, $sorter) : void

$arr = ['q' => 1, 'r' => 2, 's' => 5, 'w' => 123];

array_sort_by_keys_array($arr, ['q', 'w', 'e']);

print_r($arr);

/*
Array
(
    [q] => 1
    [w] => 123
    [r] => 2
    [s] => 5
)

echo factorial(int $n = 0) : int

echo (new \Helldar\Helpers\Support\Digits())
    ->factorial(int $n = 0) : int

echo short_number($n = 0, $precision = 1) : int|string

echo (new \Helldar\Helpers\Support\Digits($n = 0))
    ->shortNumber($precision = 1) : int|string

short_number(576);
// returns: 576

short_number(1000);
// returns: 1K

short_number(1440);
// returns: 1.4K

short_number(3000000);
// returns: 3M

short_number(3000000000);
// returns: 3B

short_number(3000000000000);
// returns: 3T+

return dd_sql($query, bool $is_short = false, bool $is_return = false) : array|string|void

return (new \Helldar\Helpers\Support\Dumper($query))
    ->ddSql($is_short, $is_return) : array|string|void

return url_file_exists($path) : bool

return (new \Helldar\Helpers\Support\Files($path))
    ->urlFileExists() : bool

return mix_url($path) : string

return (new \Helldar\Helpers\Support\Http($path))
    ->mixUrl() : string

return base_url($url) : string

return (new \Helldar\Helpers\Support\Http($url))
    ->baseUrl() : string

$parts1 = [
    'scheme' => 'http',
    'host'   => 'mysite.dev',
];

$parts2 = [
    'scheme'   => 'https',
    'host'     => 'mysite.dev',
    'port'     => 1234,
    'user'     => 'foo',
    'pass'     => 'bar',
    'path'     => '/category/subcategory',
    'query'    => 'page=1',
    'fragment' => 'section=5',
];

return build_url($parts1) : string
return (new \Helldar\Helpers\Support\Http($parts2))
    ->buildUrl();

// returned 1: http://mysite.dev
// returned 2: https://foo:[email protected]:1234/category/subcategory?page=1#section=5

return subdomain_name();

return (new \Helldar\Helpers\Support\Http())
    ->getSubdomain();

// from domain `test.mysite.local` will return `test` (string).
// from domain `mysite.local` will return `null` (null).

use Helldar\Traits\Jsonable;

class MyClass
{
    use Jsonable;

    public function __construct($data)
    {
        $this->setData($data);
    }
}

$obj = new MyClass($data);
echo $obj->toJson();

echo image_or_default(string $filename, $default = null) : string

echo (new \Helldar\Helpers\Support\Images($filename))
    ->imageOrDefault($default = null) : string

echo str_choice(int $num, array $choice = [], string $additional = '') : string

echo (new \Helldar\Helpers\Support\Str($num))
    ->choice(array $choice = [], string $additional = '') : string

echo str_choice(1, ['пользователь', 'пользователя', 'пользователей']);
// returned "пользователь"

echo str_choice(3, ['пользователь', 'пользователя', 'пользователей']);
// returned "пользователя"

echo str_choice(20, ['пользователь', 'пользователя', 'пользователей']);
// returned "пользователей"

echo str_choice(20, ['пользователь', 'пользователя', 'пользователей'], 'здесь');
// returned "пользователей здесь"

echo e($value) : string

echo (new \Helldar\Helpers\Support\Str($value))
    ->e() : string

echo de($value) : string

echo (new \Helldar\Helpers\Support\Str($value))
    ->de() : string

echo str_replace_spaces($value) : string

echo (new \Helldar\Helpers\Support\Str($value))
    ->replaceSpaces() : string

return is_windows() : bool

return (new \Helldar\Helpers\Support\System())
    ->isWindows() : bool

return is_linux() : bool

return (new \Helldar\Helpers\Support\System())
    ->isLinux() : bool

php artisan vendor:publish --provider="Helldar\Helpers\ServiceProvider"