PHPackages                             illuminated/helper-functions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. illuminated/helper-functions

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

illuminated/helper-functions
============================

Laravel-specific and pure PHP Helper Functions.

12.0.0(1y ago)107586.6k—4.8%177MITPHPPHP ^8.2CI passing

Since Jun 17Pushed 1y ago3 watchersCompare

[ Source](https://github.com/dmitry-ivanov/laravel-helper-functions)[ Packagist](https://packagist.org/packages/illuminated/helper-functions)[ RSS](/packages/illuminated-helper-functions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (124)Used By (7)

[![Laravel-specific and pure PHP Helper Functions](art/1380x575-optimized.jpg)](art/1380x575-optimized.jpg)

Laravel Helper Functions
========================

[](#laravel-helper-functions)

[![Buy me a coffee](https://user-images.githubusercontent.com/1286821/181085373-12eee197-187a-4438-90fe-571ac6d68900.png)](https://buymeacoffee.com/dmitry.ivanov)

[![StyleCI](https://camo.githubusercontent.com/cb964ee027bf82c7976f8339f2b57e0f3ac7272c2fdaf1e80f1b14200c3e800e/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f36313338343037352f736869656c643f6272616e63683d6d6173746572267374796c653d666c6174)](https://github.styleci.io/repos/61384075?branch=master)[![Build Status](https://camo.githubusercontent.com/f8c326ab51331df3e3cc00399d0b20de29e4dad266938ae1f6e6680905ca6cb0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646d697472792d6976616e6f762f6c61726176656c2d68656c7065722d66756e6374696f6e732f74657374732e796d6c3f6272616e63683d6d6173746572)](https://github.com/dmitry-ivanov/laravel-helper-functions/actions?query=workflow%3Atests+branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/72c63bd300d2b8664941b59511e76456be5b817e1034fd43cc2c0c83d68ed666/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f646d697472792d6976616e6f762f6c61726176656c2d68656c7065722d66756e6374696f6e732f6d6173746572)](https://app.codecov.io/gh/dmitry-ivanov/laravel-helper-functions/tree/master)

[![Packagist Version](https://camo.githubusercontent.com/2d290a7d175735612f4489fb2d0e7c07506f423d883a8d608388db350bc5531c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c6c756d696e617465642f68656c7065722d66756e6374696f6e73)](https://camo.githubusercontent.com/2d290a7d175735612f4489fb2d0e7c07506f423d883a8d608388db350bc5531c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c6c756d696e617465642f68656c7065722d66756e6374696f6e73)[![Packagist Stars](https://camo.githubusercontent.com/6348665f30ebd9cb681bd7af8dd6a7eddcbb9d2d9fd46a1a684738c851810749/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f696c6c756d696e617465642f68656c7065722d66756e6374696f6e73)](https://camo.githubusercontent.com/6348665f30ebd9cb681bd7af8dd6a7eddcbb9d2d9fd46a1a684738c851810749/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f696c6c756d696e617465642f68656c7065722d66756e6374696f6e73)[![Packagist Downloads](https://camo.githubusercontent.com/19a7357e5537582910152ed090ccb2ee88f7a24c1953eee87d0237cb9f0ce29f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696c6c756d696e617465642f68656c7065722d66756e6374696f6e73)](https://camo.githubusercontent.com/19a7357e5537582910152ed090ccb2ee88f7a24c1953eee87d0237cb9f0ce29f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696c6c756d696e617465642f68656c7065722d66756e6374696f6e73)[![Packagist License](https://camo.githubusercontent.com/d41c645d3ceb2f26793c72a82a311d2808eb7d99cd7d4c54a0296252ec940ad8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696c6c756d696e617465642f68656c7065722d66756e6374696f6e73)](https://camo.githubusercontent.com/d41c645d3ceb2f26793c72a82a311d2808eb7d99cd7d4c54a0296252ec940ad8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696c6c756d696e617465642f68656c7065722d66756e6374696f6e73)

Laravel-specific and pure PHP Helper Functions.

LaravelHelper Functions12.x[12.x](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/12.x)11.x[11.x](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/11.x)10.x[10.x](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/10.x)9.x[9.x](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/9.x)8.x[8.x](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/8.x)7.x[7.x](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/7.x)6.x[6.x](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/6.x)5.8.\*[5.8.\*](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/5.8)5.7.\*[5.7.\*](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/5.7)5.6.\*[5.6.\*](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/5.6)5.5.\*[5.5.\*](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/5.5)5.4.\*[5.4.\*](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/5.4)5.3.\*[5.3.\*](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/5.3)5.2.\*[5.2.\*](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/5.2)5.1.\*[5.1.\*](https://github.com/dmitry-ivanov/laravel-helper-functions/tree/5.1)Usage
-----

[](#usage)

1. Install the package via Composer:

    ```
    composer require illuminated/helper-functions
    ```
2. Use any of the provided helper functions:

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

Available functions
-------------------

[](#available-functions)

> Feel free to contribute.

- [Array](#array)

    - [array\_except\_value](#array_except_value)
    - [multiarray\_set](#multiarray_set)
    - [multiarray\_sort\_by](#multiarray_sort_by)
- [Artisan](#artisan)

    - [call\_in\_background](#call_in_background)
- [Database](#database)

    - [db\_is\_sqlite](#db_is_sqlite)
    - [db\_is\_mysql](#db_is_mysql)
    - [db\_mysql\_now](#db_mysql_now)
    - [db\_mysql\_variable](#db_mysql_variable)
- [Date](#date)

    - [to\_default\_timezone](#to_default_timezone)
- [Debug](#debug)

    - [backtrace\_as\_string](#backtrace_as_string)
    - [minimized\_backtrace\_as\_string](#minimized_backtrace_as_string)
- [Email](#email)

    - [is\_email](#is_email)
    - [to\_rfc2822\_email](#to_rfc2822_email)
    - [to\_swiftmailer\_emails](#to_swiftmailer_emails)
    - [to\_symfony\_emails](#to_symfony_emails)
- [Filesystem](#filesystem)

    - [relative\_path](#relative_path)
- [Format](#format)

    - [get\_dump](#get_dump)
    - [format\_bytes](#format_bytes)
    - [format\_xml](#format_xml)
- [Json](#json)

    - [is\_json](#is_json)
- [System](#system)

    - [is\_windows\_os](#is_windows_os)
- [Xml](#xml)

    - [xml\_to\_array](#xml_to_array)
    - [array\_to\_xml](#array_to_xml)

Array
-----

[](#array)

#### `array_except_value()`

[](#array_except_value)

Remove the given values from the array:

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

// ["foo", "bar"]
```

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

// ["foo"]
```

#### `multiarray_set()`

[](#multiarray_set)

Set the value for each item of the multidimensional array using "dot" notation:

```
$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"]],
// ]
```

#### `multiarray_sort_by()`

[](#multiarray_sort_by)

Sort the multidimensional array by several fields:

```
$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],
// ]
```

Also, you can change the sort order:

```
$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],
// ]
```

Artisan
-------

[](#artisan)

#### `call_in_background()`

[](#call_in_background)

Call the given artisan console command in background.

Code execution continues immediately, without waiting for results.

```
call_in_background('report');

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

Optional `before` and `after` sub-commands could be used:

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

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

Database
--------

[](#database)

#### `db_is_sqlite()`

[](#db_is_sqlite)

Check whether the default database connection driver is `sqlite` or not:

```
db_is_sqlite();

// false
```

#### `db_is_mysql()`

[](#db_is_mysql)

Check whether the default database connection driver is `mysql` or not:

```
db_is_mysql();

// true
```

#### `db_mysql_now()`

[](#db_mysql_now)

Get the current MySQL datetime:

```
db_mysql_now();

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

#### `db_mysql_variable()`

[](#db_mysql_variable)

Get value of the specified MySQL variable:

```
db_mysql_variable('hostname');

// "localhost"
```

Date
----

[](#date)

#### `to_default_timezone()`

[](#to_default_timezone)

Convert the given datetime to the default timezone (see `app.timezone` config):

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

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

Debug
-----

[](#debug)

#### `backtrace_as_string()`

[](#backtrace_as_string)

Get backtrace without arguments, as a string:

```
$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]
```

#### `minimized_backtrace_as_string()`

[](#minimized_backtrace_as_string)

Get minimized backtrace, as a string:

```
$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
```

Email
-----

[](#email)

#### `is_email()`

[](#is_email)

Check whether the given string is an email address or not:

```
is_email('john.doe@example.com');

// true
```

#### `to_rfc2822_email()`

[](#to_rfc2822_email)

Convert addresses data to [RFC 2822](http://faqs.org/rfcs/rfc2822.html) string, suitable for PHP [mail()](https://php.net/manual/en/function.mail.php) function:

```
to_rfc2822_email([
    ['address' => 'john.doe@example.com', 'name' => 'John Doe'],
    ['address' => 'jane.smith@example.com'],
]);

// "John Doe , jane.smith@example.com"
```

Also, it supports simplified syntax for a single address:

```
to_rfc2822_email(['address' => 'john.doe@example.com', 'name' => 'John Doe']);

// "John Doe "
```

#### `to_swiftmailer_emails()`

[](#to_swiftmailer_emails)

Convert addresses data to [SwiftMailer-suitable format](https://swiftmailer.org/docs/messages.html):

```
to_swiftmailer_emails([
    ['address' => 'john.doe@example.com', 'name' => 'John Doe'],
    ['address' => 'jane.smith@example.com'],
]);

// ["john.doe@example.com" => "John Doe", "jane.smith@example.com"]
```

Also, it supports simplified syntax for a single address:

```
to_swiftmailer_emails(['address' => 'john.doe@example.com', 'name' => 'John Doe']);

// ["john.doe@example.com" => "John Doe"]
```

#### `to_symfony_emails()`

[](#to_symfony_emails)

Convert addresses data to [Symfony-suitable format](https://symfony.com/doc/current/mailer.html#email-addresses):

```
to_symfony_emails([
    ['address' => 'john.doe@example.com', 'name' => 'John Doe'],
    ['address' => 'jane.smith@example.com'],
]);

// ["John Doe ", "jane.smith@example.com"]
```

Also, it supports simplified syntax for a single address:

```
to_symfony_emails(['address' => 'john.doe@example.com', 'name' => 'John Doe']);

// ["John Doe "]
```

Filesystem
----------

[](#filesystem)

#### `relative_path()`

[](#relative_path)

Get a relative path for the given folders:

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

// "../"
```

You can pass the relative path as a parameter too:

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

// "www/htdocs/"
```

Format
------

[](#format)

#### `get_dump()`

[](#get_dump)

Get a nicely formatted string representation of the variable, using the [Symfony VarDumper Component](https://symfony.com/doc/current/components/var_dumper/introduction.html):

```
$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()`

[](#format_bytes)

Format bytes into kilobytes, megabytes, gigabytes or terabytes:

```
format_bytes(3333333);

// "3.18 MB"
```

#### `format_xml()`

[](#format_xml)

Format the given XML string using new lines and indents:

```
format_xml('JohnJaneGo to the shopJohnPaulFinish the reportJaneJeffClean the house');

//
//
//
//     John
//     Jane
//     Go to the shop
//
//
//     John
//     Paul
//     Finish the report
//
//
//     Jane
//     Jeff
//     Clean the house
//
//
```

Json
----

[](#json)

#### `is_json()`

[](#is_json)

Check whether the given value is a valid JSON-encoded string or not:

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

// true
```

It returns decoded JSON if you pass `true` as a second argument:

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

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

System
------

[](#system)

#### `is_windows_os()`

[](#is_windows_os)

Check whether the operating system is Windows or not:

```
is_windows_os();

// false
```

Xml
---

[](#xml)

#### `xml_to_array()`

[](#xml_to_array)

Convert the given XML to array:

```
xml_to_array('

        Luke Skywalker
        Lightsaber

        Sauron
        Evil Eye

');

// [
//     "Good_guy" => [
//         "name" => "Luke Skywalker",
//         "weapon" => "Lightsaber",
//         "@attributes" => [
//             "Rating" => "100",
//         ],
//     ],
//     "Bad_guy" => [
//         "name" => "Sauron",
//         "weapon" => "Evil Eye",
//         "@attributes" => [
//             "Rating" => "90",
//         ],
//     ],
// ]
```

Alternatively, you can pass an instance of the `SimpleXMLElement` class instead of a string.

#### `array_to_xml()`

[](#array_to_xml)

Convert the given array to XML string:

```
$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');

//
//
//
//        Luke Skywalker
//        Lightsaber
//
//
//        Sauron
//        Evil Eye
//
//
```

Sponsors
--------

[](#sponsors)

[![Laravel Idea](art/sponsor-laravel-idea.png)](https://laravel-idea.com)
[![Material Theme UI Plugin](art/sponsor-material-theme.png)](https://material-theme.com)

License
-------

[](#license)

Laravel Helper Functions is open-sourced software licensed under the [MIT license](LICENSE.md).

[![Buy me a coffee](https://user-images.githubusercontent.com/1286821/181085373-12eee197-187a-4438-90fe-571ac6d68900.png)](https://buymeacoffee.com/dmitry.ivanov)

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance44

Moderate activity, may be stable

Popularity50

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Recently: every ~91 days

Total

123

Last Release

438d ago

Major Versions

7.x-dev → 8.x-dev2021-03-04

8.x-dev → 9.0.02022-02-19

9.x-dev → 10.0.02024-03-06

10.x-dev → 11.x-dev2025-03-05

11.0.0 → 12.x-dev2025-03-06

PHP version history (13 changes)0.1.1PHP &gt;=5.4.0

0.1.9PHP &gt;=5.5.9

0.1.24PHP &gt;=5.6.4

5.5.0PHP &gt;=7.0

5.6.0PHP ^7.1.3

6.0.0PHP ^7.2

7.0.0PHP ^7.2.5

8.0.0PHP ^7.3

6.2.0PHP ^7.2.5|^8.0

8.1.0PHP ^7.3|^8.0

9.0.0PHP ^8.0.2

10.0.0PHP ^8.1

11.x-devPHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b6a68d578b4021fbe05838e8e71ccd44b07879ffda6b7ec05c1deb65d0c88f8?d=identicon)[dmitry-ivanov](/maintainers/dmitry-ivanov)

---

Top Contributors

[![dmitry-ivanov](https://avatars.githubusercontent.com/u/1286821?v=4)](https://github.com/dmitry-ivanov "dmitry-ivanov (514 commits)")[![opiy-org](https://avatars.githubusercontent.com/u/10293975?v=4)](https://github.com/opiy-org "opiy-org (1 commits)")

---

Tags

array-to-xmlbackground-commandbacktracefunctionshelperslaravellaravel-packagemultiarrayxml-parserxml-to-arraylaravelhelpersBacktracefunctionsarray-to-xmlxml-to-arrayxml-parsermultiarraybackground-command

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/illuminated-helper-functions/health.svg)

```
[![Health](https://phpackages.com/badges/illuminated-helper-functions/health.svg)](https://phpackages.com/packages/illuminated-helper-functions)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.7k509.9M17.0k](/packages/laravel-framework)[wnx/laravel-stats

Get insights about your Laravel Project

1.8k1.8M7](/packages/wnx-laravel-stats)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
