PHP code example of illuminated / helper-functions

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

    

illuminated / helper-functions example snippets


    if (is_windows_os()) {
        call_in_background('switch-to-mac');
    }
    

array_except_value(['foo', 'bar', 'baz'], 'baz');

// ["foo", "bar"]

array_except_value(['foo', 'bar', 'baz'], ['bar', 'baz']);

// ["foo"]

$array = [
    ['name' => 'Mercedes-Benz', 'details' => ['type' => 'SUV']],
    ['name' => 'BMW', 'details' => ['type' => 'SUV']],
    ['name' => 'Porsche', 'details' => ['type' => 'SUV']],
];

multiarray_set($array, 'details.country', 'Germany');

// [
//     ["name" => "Mercedes-Benz", "details" => ["type" => "SUV", "country" => "Germany"]],
//     ["name" => "BMW", "details" => ["type" => "SUV", "country" => "Germany"]],
//     ["name" => "Porsche", "details" => ["type" => "SUV", "country" => "Germany"]],
// ]

$array = [
    ['name' => 'Mercedes-Benz', 'model' => 'GLS', 'price' => 120000],
    ['name' => 'Mercedes-Benz', 'model' => 'GLE Coupe', 'price' => 110000],
    ['name' => 'BMW', 'model' => 'X6', 'price' => 77000],
    ['name' => 'Porsche', 'model' => 'Cayenne', 'price' => 117000],
];

$sorted = multiarray_sort_by($array, 'name', 'model');

// [
//     ["name" => "BMW", "model" => "X6", "price" => 77000],
//     ["name" => "Mercedes-Benz", "model" => "GLE Coupe", "price" => 110000],
//     ["name" => "Mercedes-Benz", "model" => "GLS", "price" => 120000],
//     ["name" => "Porsche", "model" => "Cayenne", "price" => 117000],
// ]

$array = [
    ['name' => 'Mercedes-Benz', 'model' => 'GLS', 'price' => 120000],
    ['name' => 'Mercedes-Benz', 'model' => 'GLE Coupe', 'price' => 110000],
    ['name' => 'BMW', 'model' => 'X6', 'price' => 77000],
    ['name' => 'Porsche', 'model' => 'Cayenne', 'price' => 117000],
];

$sorted = multiarray_sort_by($array, 'name', SORT_ASC, 'model', SORT_DESC);

// [
//     ["name" => "BMW", "model" => "X6", "price" => 77000],
//     ["name" => "Mercedes-Benz", "model" => "GLS", "price" => 120000],
//     ["name" => "Mercedes-Benz", "model" => "GLE Coupe", "price" => 110000],
//     ["name" => "Porsche", "model" => "Cayenne", "price" => 117000],
// ]

call_in_background('report');

// "php artisan report" would be called in background

call_in_background('report:monthly subscriptions', 'sleep 0.3');

// "sleep 0.3 && php artisan report:monthly subscriptions" would be called in background

db_is_sqlite();

// false

db_is_mysql();

// true

db_mysql_now();

// "2020-05-25 20:09:33"

db_mysql_variable('hostname');

// "localhost"

to_default_timezone('2017-02-28T14:05:01Z');

// "2017-02-28 16:05:01", assuming that `app.timezone` is "Europe/Kiev"

$backtrace = backtrace_as_string();

#0  backtrace_as_string() called at [/htdocs/example/routes/web.php:15]
#1  Illuminate\Routing\Router->{closure}() called at [/htdocs/example/vendor/laravel/framework/src/Illuminate/Routing/Route.php:189]
#2  Illuminate\Foundation\Http\Kernel->handle() called at [/htdocs/example/public/index.php:53]

$backtrace = minimized_backtrace_as_string();

#0 /htdocs/example/routes/web.php:15
#1 /htdocs/example/vendor/laravel/framework/src/Illuminate/Routing/Route.php:189
#2 /htdocs/example/public/index.php:53

is_email('[email protected]');

// true

to_rfc2822_email([
    ['address' => '[email protected]', 'name' => 'John Doe'],
    ['address' => '[email protected]'],
]);

// "John Doe <[email protected]>, [email protected]"

to_rfc2822_email(['address' => '[email protected]', 'name' => 'John Doe']);

// "John Doe <[email protected]>"

to_swiftmailer_emails([
    ['address' => '[email protected]', 'name' => 'John Doe'],
    ['address' => '[email protected]'],
]);

// ["[email protected]" => "John Doe", "[email protected]"]

to_swiftmailer_emails(['address' => '[email protected]', 'name' => 'John Doe']);

// ["[email protected]" => "John Doe"]

to_symfony_emails([
    ['address' => '[email protected]', 'name' => 'John Doe'],
    ['address' => '[email protected]'],
]);

// ["John Doe <[email protected]>", "[email protected]"]

to_symfony_emails(['address' => '[email protected]', 'name' => 'John Doe']);

// ["John Doe <[email protected]>"]

relative_path('/var/www/htdocs', '/var/www/htdocs/example');

// "../"

relative_path('/var/www/htdocs/example/public/../../', '/var/');

// "www/htdocs/"

$array = [
    'a simple string' => 'Hello!',
    'a float' => 1.0,
    'an integer' => 1,
    'a boolean' => true,
    'an empty array' => [],
];

$dump = get_dump($array);

// array:5 [
//     "a simple string" => "Hello!"
//     "a float" => 1.0
//     "an integer" => 1
//     "a boolean" => true
//     "an empty array" => []
// ]

format_bytes(3333333);

// "3.18 MB"

format_xml('<?xml version="1.0"

is_json('{"foo":1,"bar":2,"baz":3}');

// true

is_json('{"foo":1,"bar":2,"baz":3}', true);

// ["foo" => 1, "bar" => 2, "baz" => 3]

is_windows_os();

// false

xml_to_array('<?xml version="1.0"

$array = [
    'Good guy' => [
        'name' => 'Luke Skywalker',
        'weapon' => 'Lightsaber',
        '@attributes' => [
            'Rating' => '100',
        ],
    ],
    'Bad guy' => [
        'name' => 'Sauron',
        'weapon' => 'Evil Eye',
        '@attributes' => [
            'Rating' => '90',
        ],
    ]
];

$xml = array_to_xml($array, 'Guys');

// <?xml version="1.0" encoding="utf-8"