PHP code example of anekdotes / support

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

    

anekdotes / support example snippets


use Anekdotes\Support\Arr;

use Anekdotes\Support\Str;

use Anekdotes\Support\UUID;

use Anekdotes\Support\I18n;

Arr::sortByKey([['id' => 2],['id' => 1],['id' => 3]], 'id');
// [['id' => 1],['id' => 2],['id' => 3]]

Arr::sortByKey([['id' => 2],['id' => 1],['id' => 3]], 'id', SORT_DESC);
// [['id' => 3],['id' => 2],['id' => 1]]

Arr::get(['id'=>1, 'title'=>'foo'], 'title');
// foo

//With default param if non is found
Arr::get(['id'=>1, 'title'=>'foo'], 'bar', 'toaster');
// toaster

$dummy = [
    ['id' => 1, 'name' => 'Bell'],
    ['id' => 2, 'name' => 'Lani']
];
Arr::getWhere($dummy, 'name', 'Lani');
// ['id' => 2, 'name' => 'Lani']

Arr::exists('title', ['id'=>1, 'title'=>'foo']);
// true

Arr::exists('bar', ['id'=>1, 'title'=>'foo']);
// false

$dummy = ['id'=>1, 'title'=>'foo'];
Arr::remove('title', $dummy);
$dummy // ['id'=>1]

$dummy = ['id'=>1, 'title'=>'foo'];
Arr::remove('foo', $dummy);
$dummy // ['id'=>1, 'title'=>'foo']

Str::startsWith('foo', 'f');
// true

Str::endsWith('foo', 'o');
// true

Str::split(',', '1,2,3,4,5');
// [1, 2, 3, 4, 5]

Str::capitalize('foo');
// Foo

Str::upper('foo');
// FOO

Str::lower('FOO');
// foo

Str::snakeCase('étoile filante');
// etoile_filante

Str::camelCase('foo bar');
// fooBar

Str::contains('foo', 'oo');
// true

Str::studly('foo bar');
// FooBar

Str::ascii('étoile');
// etoile

Str::slug('foo bar');
// foo-bar

Str::random();
// random 16 characters string

Str::random(20);
// random 20 characters string

Str::quickRandom();
// random quick 16 characters string

Str::quickRandom(20);
// random quick 20 characters string

Str::replace('foo', 'oo', 'yy');
// fyy

Str::regexResult('/([\w]+)/', 'foo bar', 0);
// ['foo', 'bar']