PHP code example of mellanyx / helpers

1. Go to this page and download the library: Download mellanyx/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/ */

    

mellanyx / helpers example snippets



dump(
  [
    "Peter" => [
      "age" => 18,
      "weight" => 73
    ],
    "Ben" => [
      "age" => 15,
      "weight" => 58
    ],
    "Alice" => [
      "age" => 25,
      "weight" => 75
    ]
  ]
);

Результат: см. скриншот ниже


$arr = ['one', 'two', 'bar' => ['aaa' => 'str_aaa', 'bbb' => 'str_bbb']];

p($arr);

Результат:
<pre>
Array
(
    [0] => 'one'
    [1] => 'two'
    ['bar'] => [
        ['aaa'] => 'str_aaa'
        ['bbb'] => 'str_bbb'
    ]

)
</pre>



$arr = ['one', 'two', 'bar' => ['aaa' => 'str_aaa', 'bbb' => 'str_bbb']];

l($arr);


use Mellanyx\Helpers\Utils;

Utils::numWord(5, ['товар', 'товара', 'товаров']);

Результат: 5 товаров

Utils::numWord(5, ['товар', 'товара', 'товаров'], false);

Результат: товаров


use Mellanyx\Helpers\Utils;

Utils::formatSize(1024);

Результат: 1.00 KB


use Mellanyx\Helpers\Utils;

$extras = ['#test_id','.test_class','_blank'];
Utils::anchor('https://google.com', 'Проверка связи', 'Это Title', $extras);

Результат: <a href="https://google.com" title="Это Title" id="test_id" class="test_class" target="_blank">Проверка связи</a>


use Mellanyx\Helpers\Arr;

$arr = ['one', 'two', 'bar' => ['aaa' => 'str_aaa', 'bbb' => 'str_bbb']];
Arr::isAssoc($arr);

Результат: 1


use Mellanyx\Helpers\Arr;

$arr = ['one', 'two', 'bar' => ['aaa' => 'str_aaa', 'bbb' => 'str_bbb']];
Arr::toObject($arr);

Результат:
stdClass Object
(
    [0] => one
    [1] => two
    [bar] => stdClass Object
        (
            [aaa] => str_aaa
            [bbb] => str_bbb
        )

)



use Mellanyx\Helpers\Arr;

$arr = ['one', 'two', 'bar' => ['aaa' => 'str_aaa', 'bbb' => 'str_bbb']];
Arr::arrayFirst($arr);

Результат: one


use Mellanyx\Helpers\Arr;

$arr = ['one', 'two', 'bar' => ['aaa' => 'str_aaa', 'bbb' => 'str_bbb']];
Arr::arrayLast($arr);

Результат:
Array
(
    [aaa] => str_aaa
    [bbb] => str_bbb
)


use Mellanyx\Helpers\Arr;

$arr = ['one', 'two', 'bar' => ['aaa' => 'str_aaa', 'bbb' => 'str_bbb']];
Arr::arrayGet('bar.aaa', $arr);

Результат: str_aaa


use Mellanyx\Helpers\Arr;

$arr = ['one', 'two', 'bar' => ['aaa' => 'str_aaa', 'bbb' => 'str_bbb']];
Arr::arraySet('bar.zzz', 'added from func', $arr)

Результат:
Array
(
    [0] => one
    [1] => two
    [bar] => Array
        (
            [aaa] => str_aaa
            [bbb] => str_bbb
            [zzz] => added from func
        )

)


use Mellanyx\Helpers\Str;

$keyValue = [
    ':color' => 'brown',
    ':animal' => 'dog'
];

$string = 'The quick :color fox jumps over the lazy :animal.';

Str::strInsert($keyValue, $string);

Результат: The quick brown fox jumps over the lazy dog.


use Mellanyx\Helpers\Str;

$string = 'The quick brown fox jumps over the lazy dog';

Str::limitWords($string, 3);

Результат: The quick brown...


use Mellanyx\Helpers\Str;

$string = 'The quick brown fox jumps over the lazy dog';

Str::limit($string, 15);

Результат: The quick brown...