PHPackages                             hkp22/php-helpers - 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. hkp22/php-helpers

ActiveLibrary

hkp22/php-helpers
=================

Php Helpers inspired by Laravel Helpers for non-laravel projects.

v1.01(7y ago)316MITPHPPHP &gt;=5.4.0

Since Jun 3Pushed 7y ago1 watchersCompare

[ Source](https://github.com/hkp22/php-helpers)[ Packagist](https://packagist.org/packages/hkp22/php-helpers)[ RSS](/packages/hkp22-php-helpers/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)DependenciesVersions (4)Used By (0)

PHP Helper Functions extracted from Laravel
-------------------------------------------

[](#php-helper-functions-extracted-from-laravel)

This project has extracted useful [helper functions from laravel framework](http://laravel.com/docs/5.6/helpers), which can be used outside Laravel.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require hkp22/php-helpers
```

Usage
-----

[](#usage)

- **[Arrays](#arrays)**
    - [array\_add()](#array_add)
    - [array\_build()](#array_build)
    - [array\_divide()](#array_divide)
    - [array\_dot()](#array_dot)
    - [array\_except()](#array_except)
    - [array\_first()](#array_first)
    - [array\_last()](#array_last)
    - [array\_flatten()](#array_flatten)
    - [array\_forget()](#array_forget)
    - [array\_get()](#array_get)
    - [array\_set()](#array_set)
    - [array\_has()](#array_has)
    - [array\_only()](#array_only)
    - [array\_pluck()](#array_pluck)
    - [array\_pull()](#array_pull)
    - [array\_where()](#array_where)
    - [data\_get()](#data_get)
    - [head()](#head)
    - [last()](#last)
- **[Strings](#strings)**
    - [camel\_case()](#camel_case)
    - [class\_basename()](#class_basename)
    - [e()](#e)
    - [ends\_with()](#ends_with)
    - [studly\_case()](#studly_case)
- **[Miscellaneous](#miscellaneous)**
    - [class\_uses\_recursive()](#class_uses_recursive)
    - [dd()](#dd)
    - [trait\_uses\_recursive()](#trait_uses_recursive)
    - [value()](#value)

Arrays
------

[](#arrays)

### `array_add()`

[](#array_add)

The `array_add` function adds a given key/value pair to an array if the given key doesn't already exist in the array:

```
$array = array_add(['name' => 'Desk'], 'price', 100);

// ['name' => 'Desk', 'price' => 100]
```

### `array_build()`

[](#array_build)

Build a new array using a callback.

```
$array = [
    'us' => 'united states',
    'uk' => 'united kingdom',
    'in' => 'india',
  ];

// run array_build function
$result = array_build($array, function ($key, $value) {
    return [strtoupper($key), ucwords($value)];
});

// Output
// ['US' => 'United States', 'UK' => 'United Kingdom', 'IN' => 'India']
```

### `array_divide()`

[](#array_divide)

The `array_divide` function returns two arrays, one containing the keys, and the other containing the values of the given array:

```
[$keys, $values] = array_divide(['name' => 'Desk']);

// $keys: ['name']

// $values: ['Desk']
```

### `array_dot()`

[](#array_dot)

The `array_dot` function flattens a multi-dimensional array into a single level array that uses "dot" notation to indicate depth:

```
$array = ['products' => ['desk' => ['price' => 100]]];

$flattened = array_dot($array);

// ['products.desk.price' => 100]
```

### `array_except()`

[](#array_except)

The `array_except` function removes the given key / value pairs from an array:

```
$array = ['name' => 'Desk', 'price' => 100];

$filtered = array_except($array, ['price']);

// ['name' => 'Desk']
```

### `array_first()`

[](#array_first)

The `array_first` function returns the first element of an array passing a given truth test:

```
$array = [100, 200, 300];

$value = array_first($array, function ($key, $value) {
    return $value >= 150;
});

// 200
```

### `array_last()`

[](#array_last)

The `array_last` function returns the last element of an array passing a given truth test:

```
$array = [100, 200, 300, 110];

$last = array_last($array, function ($key, $value) {
    return $value >= 150;
});

// 300
```

### `array_flatten()`

[](#array_flatten)

The `array_flatten` function flattens a multi-dimensional array into a single level array:

```
$array = ['name' => 'Joe', 'languages' => ['PHP', 'Ruby']];

$flattened = array_flatten($array);

// ['Joe', 'PHP', 'Ruby']
```

### `array_forget()`

[](#array_forget)

The `array_forget` function removes a given key / value pair from a deeply nested array using "dot" notation:

```
$array = ['products' => ['desk' => ['price' => 100]]];

array_forget($array, 'products.desk');

// ['products' => []]
```

### `array_get()`

[](#array_get)

The `array_get` function retrieves a value from a deeply nested array using "dot" notation:

```
$array = ['products' => ['desk' => ['price' => 100]]];

$price = array_get($array, 'products.desk.price');

// 100
```

### `array_set()`

[](#array_set)

The `array_set` function sets a value within a deeply nested array using "dot" notation:

```
$array = ['products' => ['desk' => ['price' => 100]]];

array_set($array, 'products.desk.price', 200);

// ['products' => ['desk' => ['price' => 200]]]
```

`array_has()`
-------------

[](#array_has)

The `array_has` function checks whether a given item or items exists in an array using "dot" notation:

```
$array = ['product' => ['name' => 'Desk', 'price' => 100]];

$contains = array_has($array, 'product.name');

// true

$contains = array_has($array, ['product.price', 'product.discount']);

// false
```

### `array_only()`

[](#array_only)

The `array_only` function returns only the specified key / value pairs from the given array:

```
$array = ['name' => 'Desk', 'price' => 100, 'orders' => 10];

$slice = array_only($array, ['name', 'price']);

// ['name' => 'Desk', 'price' => 100]
```

### `array_pluck()`

[](#array_pluck)

The `array_pluck` function retrieves all of the values for a given key from an array:

```
$array = [
    ['developer' => ['id' => 1, 'name' => 'Taylor']],
    ['developer' => ['id' => 2, 'name' => 'Abigail']],
];

$names = array_pluck($array, 'developer.name');

// ['Taylor', 'Abigail']
```

You may also specify how you wish the resulting list to be keyed:

```
$names = array_pluck($array, 'developer.name', 'developer.id');

// [1 => 'Taylor', 2 => 'Abigail']
```

### `array_pull()`

[](#array_pull)

The `array_pull` function returns and removes a key / value pair from an array:

```
$array = ['name' => 'Desk', 'price' => 100];

$name = array_pull($array, 'name');

// $name: Desk

// $array: ['price' => 100]
```

A default value may be passed as the third argument to the method. This value will be returned if the key doesn't exist:

```
$value = array_pull($array, $key, $default);
```

### `array_where()`

[](#array_where)

The `array_where` function filters an array using the given Closure:

```
$array = [100, '200', 300, '400', 500];

$filtered = array_where($array, function ($value, $key) {
    return is_string($value);
});

// [1 => '200', 3 => '400']
```

### `data_get()`

[](#data_get)

The `data_get` function retrieves a value from a nested array or object using "dot" notation:

```
$data = ['products' => ['desk' => ['price' => 100]]];

$price = data_get($data, 'products.desk.price');

// 100
```

### `head()`

[](#head)

The `head` function returns the first element in the given array:

```
$array = [100, 200, 300];

$first = head($array);

// 100
```

### `last()`

[](#last)

The `last` function returns the last element in the given array:

```
$array = [100, 200, 300];

$last = last($array);

// 300
```

Strings
-------

[](#strings)

### `camel_case()`

[](#camel_case)

The `camel_case` function converts the given string to `camelCase`:

```
$converted = camel_case('foo_bar');

// fooBar
```

### `class_basename()`

[](#class_basename)

The `class_basename` returns the class name of the given class with the class' namespace removed:

```
$class = class_basename('Foo\Bar\Baz');

// Baz
```

### `e()`

[](#e)

The `e` function runs PHP's `htmlspecialchars` function with the `double_encode` option set to `true` by default:

```
echo e('foo');

// &lt;html&gt;foo&lt;/html&gt;
```

### `ends_with()`

[](#ends_with)

The `ends_with` function determines if the given string ends with the given value:

```
$result = ends_with('This is my name', 'name');

// true
```

### `studly_case()`

[](#studly_case)

The `studly_case` function converts the given string to `StudlyCase`:

```
$converted = studly_case('foo_bar');

// FooBar
```

Miscellaneous
-------------

[](#miscellaneous)

### `class_uses_recursive()`

[](#class_uses_recursive)

The `class_uses_recursive` function returns all traits used by a class, including traits used by all of its parent classes:

```
$traits = class_uses_recursive(App\User::class);
```

### `dd()`

[](#dd)

The `dd` function dumps the given variables and ends execution of the script:

```
dd($value);

dd($value1, $value2, $value3, ...);
```

### `trait_uses_recursive()`

[](#trait_uses_recursive)

The `trait_uses_recursive` function returns all traits used by a trait:

```
$traits = trait_uses_recursive(\Illuminate\Notifications\Notifiable::class);
```

### `value()`

[](#value)

The `value` function returns the value it is given. However, if you pass a Closure to the function, the Closure will be executed then its result will be returned:

```
$result = value(true);

// true

$result = value(function () {
    return false;
});

// false
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~10 days

Total

2

Last Release

2887d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/409368752f65ba14c0c6bfaabf70353b13096503e1de1e13d3e6aa3899cb13aa?d=identicon)[hkp22](/maintainers/hkp22)

---

Top Contributors

[![hkp22](https://avatars.githubusercontent.com/u/39181262?v=4)](https://github.com/hkp22 "hkp22 (12 commits)")

---

Tags

phplaravelhelperslaravel-helpersphp-helpers

### Embed Badge

![Health badge](/badges/hkp22-php-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/hkp22-php-helpers/health.svg)](https://phpackages.com/packages/hkp22-php-helpers)
```

###  Alternatives

[dragon-code/support

Support package is a collection of helpers and tools for any project.

238.7M100](/packages/dragon-code-support)[event4u/data-helpers

Framework-agnostic PHP library for data mapping, DTOs and utilities. Includes DataMapper, SimpleDto/LiteDto, DataAccessor/Mutator/Filter and helper classes (MathHelper, EnvHelper, etc.). Works with Laravel, Symfony/Doctrine or standalone PHP.

1421.5k](/packages/event4u-data-helpers)[transprime-research/piper

PHP Pipe method execution with values from chained method executions

174.6k2](/packages/transprime-research-piper)

PHPackages © 2026

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