PHPackages                             amhislop/php-snippets-for-js-devs - 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. amhislop/php-snippets-for-js-devs

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

amhislop/php-snippets-for-js-devs
=================================

PHP Snippets for JavaScript Developers

v1.0.0(4y ago)19[1 issues](https://github.com/amhislop/php-snippets-for-js-devs/issues)[1 PRs](https://github.com/amhislop/php-snippets-for-js-devs/pulls)MITPHPCI passing

Since Nov 12Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/amhislop/php-snippets-for-js-devs)[ Packagist](https://packagist.org/packages/amhislop/php-snippets-for-js-devs)[ Docs](https://github.com/amhislop/php-snippets-for-js-devs)[ RSS](/packages/amhislop-php-snippets-for-js-devs/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (1)Versions (8)Used By (0)

@amhislop/php-snippets-for-js-devs
==================================

[](#amhislopphp-snippets-for-js-devs)

PHP Snippets for JavaScript Developers
======================================

[](#php-snippets-for-javascript-developers)

[![](https://camo.githubusercontent.com/d892aab55a10aa938fa5b1dc0d0d146cf4b16768c0680da6b9e96272c3473070/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d312e302e302d626c75653f7374796c653d666c6174)](https://camo.githubusercontent.com/d892aab55a10aa938fa5b1dc0d0d146cf4b16768c0680da6b9e96272c3473070/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d312e302e302d626c75653f7374796c653d666c6174)[![](https://camo.githubusercontent.com/15c9d26825cea393ff5825379964d12485ddcd95897edaf405e5e6a3a851149e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e312b2d626c75653f7374796c653d666c6174266c6f676f3d706870)](https://camo.githubusercontent.com/15c9d26825cea393ff5825379964d12485ddcd95897edaf405e5e6a3a851149e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e312b2d626c75653f7374796c653d666c6174266c6f676f3d706870)

[![](/php-js-dummy-logo.svg)](/php-js-dummy-logo.svg)
-----------------------------------------------------

[](#)

A collection of immutable array functions for PHP that JS devs know and love.

Functions
---------

[](#functions)

- [array\_some](##array_some)
- [array\_every](##array_every)
- [array\_find](##array_find)
- [array\_sort](##array_sort)
- [array\_flat](##array_flat)
- [array\_entries](##array_entries)
- [array\_from\_entries](##array_from_entries)

Documentation
-------------

[](#documentation)

### array\_some

[](#array_some)

---

#### Definition

[](#definition)

```
array_some( callable $callback, array $array ) : bool

```

The array\_some function checks if any elements in an array pass a conditional set by a callback function and returns a boolean based on whether the condition in callback is met for at least one array item.

**JS Equivilant**: *Array.some()*

#### Parameters

[](#parameters)

- **callback** - The function to execute per iteration

    ```
    callback( mixed $item [, int $index ] ) : bool

    ```

    - **item** - The current iteration
    - **index** - The current index
- **array** - The array to be iterated over

#### Return Values

[](#return-values)

Returns a boolean based on whether the condition in callback is met for at least one array item.

#### Usage

[](#usage)

```
$nums = [13, 85, 15, 23];

$result = array_some(function ($num) {
  return $num > 60;
}, $nums);

// $result: TRUE
```

### array\_every

[](#array_every)

---

#### Definition

[](#definition-1)

```
array_every( callable $callback, array $array ) : bool

```

The array\_every function checks if all elements in an array pass a conditional set by a callback function and returns a boolean based on whether condition in callback is met for all array items.

**JS Equivilant**: *Array.every()*

#### Parameters

[](#parameters-1)

- **callback** - The function to execute per iteration

    ```
    callback( mixed $item [, int $index ] ) : bool

    ```

    - **item** - The current iteration
    - **index** - The current index
- **array** - The array to be iterated over

#### Return Values

[](#return-values-1)

Returns a boolean based on whether condition in callback is met for all array items.

#### Usage

[](#usage-1)

```
$nums = [13, 85, 15, 'John'];

$result = array_every(function ($num) {
  return is_numeric($num);
}, $nums);

// $result: FALSE
```

### array\_find

[](#array_find)

---

#### Definition

[](#definition-2)

```
array_find( callable $callback, array $array ) : mixed

```

The array\_find function iterates through an array and returns the first item which meets the condition returned from the callback function.

**JS Equivilant**: *Array.find()*

#### Parameters

[](#parameters-2)

- **callback** - The function to execute per iteration

    ```
    callback( mixed $item [, int $index ] ) : bool

    ```

    - **item** - The current iteration
    - **index** - The current index
- **array** - The array to be iterated over

#### Return Values

[](#return-values-2)

Returns the first item which meets the condition returned from the callback function. If none of the items in the array meed the condtion the function NULL is returned

#### Usage

[](#usage-2)

```
$names = ['Sam', 'Damo', 'Kate', 'Lucy'];

$result = array_find(function ($name) {
  return $name === 'Lucy';
}, $names);

// $result: 'Lucy'
```

### array\_sort

[](#array_sort)

---

#### Definition

[](#definition-3)

```
array_sort( array $array [, callable $callback ] ) : array

```

The array\_sort function sorts the items of a given array based on positive, neutral or negative values returned from the callback function or if a callback is not supplied the array will be sorted based on numerical or alphabetical values.

**JS Equivilant**: *Array.sort()*

#### Parameters

[](#parameters-3)

- **array** - The array to be sorted
- **callback** - A function that compares two consecutive values in the array ```
    callback( mixed $first, mixed $second ) : bool

    ```

    - **first** - The first item for comparison.
    - **second** - The second item for comparison.

#### Return Values

[](#return-values-3)

The sorted array

#### Usage

[](#usage-3)

```
$nums = [1, 7, 3, 2, 8];

// Sort in descending order
$desc_nums = array_sort($nums, function ($first, $second) {
  return $second - $first;
});
// $desc_nums: [ 8, 7, 3, 2, 1 ]

// Sort in ascending order
$asc_nums = array_sort($nums);
// $asc_nums: [ 1, 2, 3, 7, 8 ]
```

### array\_flat

[](#array_flat)

---

#### Definition

[](#definition-4)

```
array_flat( array $array [, mixed $depth = 1 ] ): array

```

The array\_flat function creates a new array with all sub-array elements added into it recursively up to the specified depth. The predifined INF constant can be passed in to indicate infinate depth.

**JS Equivilant** *Array.flat()*

#### Paramaters

[](#paramaters)

- **array** - The nested array to be flattened
- **depth** - Specifies how deep a nested array structure should be flattened. Defaults to 1.

#### Return Values

[](#return-values-4)

The new array with the sub-array values concatenated into it.

#### Usage

[](#usage-4)

```
$data = [ 1, 2, [ 3, 4, [ 5, 6, [ 7, 8 ] ] ] ];

$flattened_array = array_flat( $data, 2 );

// $flattened_array = [ 1, 2, 3, 4, 5, 6, [ 7, 8 ] ];
```

### array\_entries

[](#array_entries)

---

#### Definition

[](#definition-5)

```
array_entries( array $array ) : array

```

The array\_entries function returns a new array containing arrays of the keys and values of the given array

**JS Equivilant**: *Object.entries()*

#### Parameters

[](#parameters-4)

- **array** - The array whos *\[key =&gt; value\]* pairs are to be returned

#### Return Values

[](#return-values-5)

An array of arrays containing the given arays *\[key =&gt; value\]* pairs

#### Usage

[](#usage-5)

```
$key_value_array = [
  'Maths' => 95,
  'Physics' => 90,
  'Chemistry' => 96,
  'English' => 93,
  'Computer' => 90
];

$entries = array_entries($key_value_array);
// $entries: [
//   [ 'Maths', 95 ],
//   [ 'Physics', 90 ],
//   [ 'Chemistry', 96 ],
//   [ 'English', 93 ],
//   [ 'Computer', 90 ]
// ];
```

### array\_from\_entries

[](#array_from_entries)

---

#### Definition

[](#definition-6)

```
array_from_entries( array $array ) : array

```

The array\_from\_entries function restores a new *\[key =&gt; value\]* array based on the arrays provided by the given array.

**JS Equivilant**: *Object.fromEntries()*

#### Parameters

[](#parameters-5)

- **array** - The array whos arrays are to be restored to a string-keyed *\[key =&gt; value\]* format

#### Return Values

[](#return-values-6)

A new array of keyed properties matching the given arrays items

#### Usage

[](#usage-6)

```
$entries = [
  ['Maths', 95],
  ['Physics', 90],
  ['Chemistry', 96],
  ['English', 93],
  ['Computer', 90]
];

$key_value_array = array_from_entries($entries);

// $key_value_array: [
//   "Maths"  =>	95,
//   "Physics"  =>	90,
//   "Chemistry"  =>	96,
//   "English"  =>	93,
//   "Computer" =>	90
// ];
```

License
-------

[](#license)

MIT © [amhislop](https://github.com/amhislop)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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 ~147 days

Total

4

Last Release

1569d ago

Major Versions

v0.3-beta → v1.0.02022-01-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31024174?v=4)[Aidan Hislop](/maintainers/amhislop)[@amhislop](https://github.com/amhislop)

---

Top Contributors

[![amhislop](https://avatars.githubusercontent.com/u/31024174?v=4)](https://github.com/amhislop "amhislop (14 commits)")

---

Tags

utilitysnippets

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amhislop-php-snippets-for-js-devs/health.svg)

```
[![Health](https://phpackages.com/badges/amhislop-php-snippets-for-js-devs/health.svg)](https://phpackages.com/packages/amhislop-php-snippets-for-js-devs)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[voku/arrayy

Array manipulation library for PHP, called Arrayy!

4875.5M16](/packages/voku-arrayy)[mage2tv/magento-cache-clean

This package has been migrated to mage-os/magento-cache-clean. Please switch over at your convenience.

5432.1M3](/packages/mage2tv-magento-cache-clean)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[lodash-php/lodash-php

A port of Lodash to PHP

527719.0k5](/packages/lodash-php-lodash-php)

PHPackages © 2026

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