PHPackages                             snicco/str-arr - 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. snicco/str-arr

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

snicco/str-arr
==============

A standalone implementation of Laravel's Str and Arr classes.

v1.10.1(1y ago)522.0k9LGPL-3.0-onlyPHPPHP ^7.4|^8.0

Since Apr 17Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (35)Used By (9)

Snicco - Zero dependency string and array helpers
=================================================

[](#snicco---zero-dependency-string-and-array-helpers)

[![codecov](https://camo.githubusercontent.com/a99e6ec528fffd1664e95534f9a09a4a09d2afe62799ff0d8774dc22d8453f6c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d3130302532352d73756363657373)](https://codecov.io/gh/snicco/snicco)[![Psalm Type-Coverage](https://camo.githubusercontent.com/c12cfed65c7da16501f7a84e7861b8c4757fc30e9dc00bb2983783dbb3f3f84c/68747470733a2f2f73686570686572642e6465762f6769746875622f736e6963636f2f736e6963636f2f636f7665726167652e7376673f)](https://shepherd.dev/github/snicco/snicco)[![Psalm level](https://camo.githubusercontent.com/c5e90ffcf3a5aa1f78f93bddde5db7627b114329393aa87697df8cedc7f5391a/68747470733a2f2f73686570686572642e6465762f6769746875622f736e6963636f2f736e6963636f2f6c6576656c2e7376673f)](https://psalm.dev/)[![PhpMetrics - Static Analysis](https://camo.githubusercontent.com/364ffb28ea219affd0fed2e99cc046bac0bf41da3f1d3814e0cbe4a4bb54c994/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5068704d6574726963732d5374617469635f416e616c797369732d326561343466)](https://snicco.github.io/snicco/phpmetrics/StrArr/index.html)[![PHP-Versions](https://camo.githubusercontent.com/241a10d25aa09d5e8a82ebd2b55780a63dd43736d958d4004c3166e650874aca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545372e34253743253545382e30253743253545382e312d626c7565)](https://camo.githubusercontent.com/241a10d25aa09d5e8a82ebd2b55780a63dd43736d958d4004c3166e650874aca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545372e34253743253545382e30253743253545382e312d626c7565)

This package contains a subset of the [`illuminate/support`](https://github.com/illuminate/support) `Str` and `Arr`classes.

Laravel's string and array helpers are very handy utility classes but [pulling in the entire `illuminate/support` is not an option](https://mattallan.me/posts/dont-use-illuminate-support)when you are writing a framework-agnostic package.

The following modifications have been made:

`Str`:

- full multibyte support for all methods
- strict-typehints
- `Str` is a final class
- all hidden `illuminate/*` dependencies are removed
- full support for `@psalm`.

`Arr`:

- strict-typehints
- `Arr` is a final class
- all hidden `illuminate/*` dependencies are removed
- `Collection` references are replaces with `ArrayAccess` or `ArrayObject` where applicable
- full support for `@psalm` and `@template` annotations.

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

[](#installation)

```
composer require snicco/str-arr
```

Usage
-----

[](#usage)

This package is pretty much self-documenting.

Check the source ([`Str`](src/Str.php), [`Arr`](src/Arr.php)) and tests ([`Str`](tests/StrTest.php), [`Arr`](tests/ArrTest.php))

Public API of [`Str`](src/Str.php):

```
use Snicco\Component\StrArr\Str;

$subject = 'snicco.io';

Str::contains($subject, '.io') // true
Str::containsAll($subject, ['.io', '.com']) // false
Str::containsAny($subject, ['.io', '.com']) // true

Str::studly('snicco str-arr'); // Snicco StrArr

Str::ucfirst($subject); // Snicco.io

Str::startsWith($subject, 'snicco') // true

Str::endsWith($subject, '.io') // true
Str::doesNotEndWith($subject, '.io') // false

Str::afterFirst($subject, 'c') // co.io
Str::afterLast($subject, 'c') // o.io

Str::betweenFirst($subject, 'c', 'o') // o
Str::betweenLast($subject, 'c', 'o') // co.io

Str::beforeFirst($subject, 'o') // snicc
Str::beforeLast($subject, 'o') // snicco.i

Str::substr($subject, -3) // .io

// This accepts any regex pattern. * will be replaced with ".*"
Str::is($subject, 'snicco.*') // true

Str::replaceFirst($subject, 'c', 'k') // snikco.io
Str::replaceAll($subject, 'c', 'k') // snikko.io

Str::pregReplace($subject, 'c', '/\.\w{2}/', '.de') // snicco.de
```

Public API of [`Arr`](src/Arr.php):

```
use Snicco\Component\StrArr\Arr;use Snicco\Component\StrArr\Str;

$array = [
    'foo' => 'bar'
    'baz' => 'biz'
    'boom' => [
        'bang' => 'pow'
    ]
]

Arr::only($array, ['foo']) // ['foo'=>'bar']

// Returns the first array element
Arr::first($array) // bar

// Returns the first element matching the condition
Arr::first(
    $array,
    fn(string $value, string $key) => Str::startsWith($key, 'f')
); // bar

// With a default value
Arr::first($array, fn($value) => is_int($value), 'default') // default

Arr::random($array, 1) // returns one random value.

Arr::toArray('foo') // ['foo']
Arr::toArray([]) // []
Arr::toArray(['foo']) // ['foo']

// Checks if all keys are strings
Arr::isAssoc($array) // true

Arr::isList($array) // false
Arr::isList(['foo', 'bar']) // true

Arr::get($array, 'foo') // bar
Arr::get($array, 'bogus') // null
Arr::get($array, 'bogus', 'default') // default
Arr::get($array, 'boom.bang') // pow

// passed by reference here
Arr::set($array, 'boom.bang', 'POW');

Arr::has($array, 'foo') // true
Arr::has($array, 'bogus') // false
Arr::has($array, 'boom.bang') // true

Arr::hasAll(['foo', 'bogus']) // false

Arr::hasAny(['foo', 'bogus']) // true

// Checks if the passed value is either array or ArrayAccess
Arr::accessible($array) // true

Arr::mergeRecursive($array, ['boom' => ['bang' => 'POW', 'new' => 'NEW']])
// [ 'foo' => 'bar'
//    'baz' => 'biz'
//    'boom' => [
//        'bang' => 'POW',
//        'new => 'NEW'
//    ]
// ]

Arr::keyExists($array, 'foo') // true

Arr::flatten($array) // ['bar', 'biz', 'pow']

Arr::except($array, ['foo', 'baz'])
// [
//    'boom' => [
//        'bang' => 'POW',
//        'new => 'NEW'
//    ]
// ]

// Passed by reference here
Arr::remove($array, 'boom.bang');
// [ 'foo' => 'bar'
//    'baz' => 'biz'
//    'boom' => []
// ]
```

Contributing
------------

[](#contributing)

This repository is a read-only split of the development repo of the [**Snicco** project](https://github.com/snicco/snicco).

[This is how you can contribute](https://github.com/snicco/snicco/blob/master/CONTRIBUTING.md).

Reporting issues and sending pull requests
------------------------------------------

[](#reporting-issues-and-sending-pull-requests)

Please report issues in the [**Snicco** monorepo](https://github.com/snicco/snicco/blob/master/CONTRIBUTING.md##using-the-issue-tracker).

Security
--------

[](#security)

If you discover a security vulnerability, please follow our [disclosure procedure](https://github.com/snicco/snicco/blob/master/SECURITY.md).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

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

Recently: every ~1 days

Total

33

Last Release

618d ago

Major Versions

v1.10.0 → v2.0.0-beta.12024-09-01

v1.10.1 → v2.0.0-beta.72024-09-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/d659a021c9077ceb60e6ab1ea4287b9f209edb97e93bceceb7fb539d8302e894?d=identicon)[calvinalkan](/maintainers/calvinalkan)

---

Top Contributors

[![snicco-bot](https://avatars.githubusercontent.com/u/101470239?v=4)](https://github.com/snicco-bot "snicco-bot (25 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/snicco-str-arr/health.svg)

```
[![Health](https://phpackages.com/badges/snicco-str-arr/health.svg)](https://phpackages.com/packages/snicco-str-arr)
```

###  Alternatives

[zhuqipeng/laravel-hprose

Hprose for Laravel

605.8k1](/packages/zhuqipeng-laravel-hprose)

PHPackages © 2026

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