PHPackages                             yii2mod/yii2-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yii2mod/yii2-helpers

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

yii2mod/yii2-helpers
====================

Collection of useful helper functions for Yii Framework 2.0

1.3(9y ago)15177.5k↓14.1%6[1 issues](https://github.com/yii2mod/yii2-helpers/issues)[1 PRs](https://github.com/yii2mod/yii2-helpers/pulls)5MITPHP

Since Sep 2Pushed 9y ago4 watchersCompare

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

READMEChangelog (7)Dependencies (3)Versions (8)Used By (5)

Yii2 Helpers
============

[](#yii2-helpers)

This extension is a collection of useful helper functions for Yii Framework 2.0.

[![Latest Stable Version](https://camo.githubusercontent.com/96c3bee9e9f0b65d053c9d53220959587b90dfd01f1ec9885671f9073a9e4bbe/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d68656c706572732f762f737461626c65)](https://packagist.org/packages/yii2mod/yii2-helpers) [![Total Downloads](https://camo.githubusercontent.com/f06f878f406068eac2e56609d7b49994312fc465f7c35a7742b6f24a89ab373f/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d68656c706572732f646f776e6c6f616473)](https://packagist.org/packages/yii2mod/yii2-helpers) [![License](https://camo.githubusercontent.com/5bfa014c73756659857c6b24d8ecb756208bb7fc7a337d5b129e12e73bfb6cf8/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d68656c706572732f6c6963656e7365)](https://packagist.org/packages/yii2mod/yii2-helpers) [![Build Status](https://camo.githubusercontent.com/44817b34fa5c893b7ae808ce219aee5e737804626080514799bedf69dde24464/68747470733a2f2f7472617669732d63692e6f72672f796969326d6f642f796969322d68656c706572732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yii2mod/yii2-helpers)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist yii2mod/yii2-helpers "*"

```

or add

```
"yii2mod/yii2-helpers": "*"

```

to the require section of your `composer.json` file.

Available Methods
-----------------

[](#available-methods)

1. **[add()](#add)**
2. **[average()](#average)**
3. **[collapse()](#collapse)**
4. **[except()](#except)**
5. **[has()](#has)**
6. **[first()](#first)**
7. **[flatten()](#flatten)**
8. **[last()](#last)**
9. **[only()](#only)**
10. **[pluck()](#pluck)**
11. **[prepend()](#prepend)**
12. **[pull()](#pull)**
13. **[set()](#set)**
14. **[sort()](#sort)**
15. **[sortRecursive()](#sortrecursive)**
16. **[where()](#where)**
17. **[xmlStrToArray()](#xmlstrtoarray)**

Method Listing
--------------

[](#method-listing)

\#####`add()`

Add a given key / value pair to the array if the given key doesn't already exist in the array:

```
$array = ArrayHelper::add(['card' => 'Visa'], 'price', 200);
// ['card' => 'Visa', 'price' => 200]
```

---

\#####`average()`

Get the average value of a given key:

```
ArrayHelper::average([1, 2, 3, 4, 5]);
// 3
```

You may also pass a key to the average method:

```
$array = [
   ['score' => 10],
   ['score' => 30],
   ['score' => 50],
];

ArrayHelper::average($array, 'score');

// 30
```

---

\#####`collapse()`

Collapse an array of arrays into a single array:

```
$array = ArrayHelper::collapse([[1, 2, 3], [4, 5, 6]]);

// [1, 2, 3, 4, 5, 6]
```

---

\#####`except()`

Get all of the given array except for a specified array of items:

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

$array = ArrayHelper::except($array, ['price']);

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

---

\#####`has()`

Check if an item exists in an array using "dot" notation:

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

$hasDesk = ArrayHelper::has($array, 'products.desk');

// true
```

---

\#####`first()`

Return the first element in an array passing a given truth test:

```
$array = [100, 200, 300];
$value = ArrayHelper::first($array); // 100

// or apply custom callback

$value = ArrayHelper::first($array, function($key, $value) {
      return $value >= 150; // 200
});
```

---

\#####`flatten()`

Flatten a multi-dimensional array into a single level:

```
$array = ['name' => 'Bob', 'languages' => ['PHP', 'Python']];

$array = ArrayHelper::flatten($array);

// ['Bob', 'PHP', 'Python'];
```

---

\#####`last()`

Return the last element in an array passing a given truth test:

```
$array = [100, 200, 300];
$value = ArrayHelper::last($array); // 300

// or apply custom callback

$value = ArrayHelper::last($array, function($key, $value) {
      return $value; // 300
});
```

---

\#####`only()`

Get a subset of the items from the given array:

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

$array = ArrayHelper::only($array, ['name', 'price']);

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

---

\#####`prepend()`

Push an item onto the beginning of an array:

```
$array = ['one', 'two', 'three', 'four'];

$array = ArrayHelper::prepend($array, 'zero');

// $array: ['zero', 'one', 'two', 'three', 'four']
```

---

\#####`pluck()`

The function retrieves all of the collection values for a given key:

```
$array = [
   ['product_id' => 'prod-100', 'name' => 'Desk'],
   ['product_id' => 'prod-200', 'name' => 'Chair'],
];

$plucked = ArrayHelper::pluck($array, 'name');

// ['Desk', 'Chair']
```

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

```
$plucked = ArrayHelper::pluck($array, 'name', 'product_id');

// ['prod-100' => 'Desk', 'prod-200' => 'Chair']
```

---

\#####`pull()`

Get a value from the array, and remove it:

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

$name = ArrayHelper::pull($array, 'name');

// $name: Desk

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

---

\#####`set()`

Set an array item to a given value using "dot" notation:

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

ArrayHelper::set($array, 'products.desk.price', 200);

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

---

\#####`sort()`

Sort the array using the given callback:

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

$array = ArrayHelper::sort($array, function ($value) {
    return $value['name'];
});

/*
    [
        ['name' => 'Chair'],
        ['name' => 'Desk'],
    ]
*/
```

---

\#####`sortRecursive()`

Recursively sort an array by keys and values:

```
$array = [
      [
          'Desc',
          'Chair',
      ],
      [
          'PHP',
          'Ruby',
          'JavaScript',
      ],
];

$array = ArrayHelper::sortRecursive($array);

/*
  [
      [
         'Chair',
         'Desc',
      ],
      [
         'JavaScript',
         'PHP',
         'Ruby',
      ]
  ];
*/
```

---

\#####`where()`

Filter the array using the given Closure.:

```
$array = ["100", 200, "300"];
$value = ArrayHelper::where($array, function($key, $value) {
   return is_string($value);
});
// Will be return Array ( [0] => 100 [2] => 300 );
```

---

\#####`xmlStrToArray()`

Convert xml string to array.

```
$xml = '

            1
            Bob
          ';

ArrayHelper::xmlStrToArray($xml)

// ['id' => 1, 'name' => 'Bob']
```

\####StringHelper

- `StringHelper::removeStopWords('some text');` - remove stop words from string
- `StringHelper::removePunctuationSymbols('some text');` - Remove punctuation symbols from string

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

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

Recently: every ~54 days

Total

7

Last Release

3464d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a53a15e1548ce60ee92591e71492a39eaaecfc88eaa1a9d7f353d5c910381de?d=identicon)[disem](/maintainers/disem)

---

Tags

yii2yii2-array-helperyii2-extensionyii2-string-helperyii2yii2 helpersyii2 array helpers

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/yii2mod-yii2-helpers/health.svg)

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

###  Alternatives

[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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