PHPackages                             funct/funct - 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. funct/funct

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

funct/funct
===========

A PHP library with commonly used code blocks

1.6.0(1y ago)605141.2k↓46.3%40[3 issues](https://github.com/phpfunct/funct/issues)[2 PRs](https://github.com/phpfunct/funct/pulls)20MITPHPCI failing

Since Nov 12Pushed 1y ago33 watchersCompare

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

READMEChangelog (8)Dependencies (1)Versions (10)Used By (20)

[![Funct](https://camo.githubusercontent.com/63d231ce19b55097d348d97c799f10182ebf6ed8af9a5ce48ec62c5523ba1351/687474703a2f2f692e696d6775722e636f6d2f6a744b6a5766762e706e67)](https://camo.githubusercontent.com/63d231ce19b55097d348d97c799f10182ebf6ed8af9a5ce48ec62c5523ba1351/687474703a2f2f692e696d6775722e636f6d2f6a744b6a5766762e706e67)

A PHP library with commonly used code blocks for faster development

```
Funct\firstValueNotEmpty($a, $b, $c)
```

[![Latest Version](https://camo.githubusercontent.com/bc1e65dd5946f478d486347aa630a7c6341e02c69bf54b43211c95431e51b682/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f70687066756e63742f66756e63742e7376673f7374796c653d666c61742d737175617265)](https://github.com/phpfunct/funct/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/209933485d82a465d18ccab56e193932eb515aea14580bba59a58026c24659bd/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f70687066756e63742f66756e63742e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/phpfunct/funct)[![Code Coverage](https://camo.githubusercontent.com/14436072d6317f466d5ed07b9bdf3a91fa5789d57d45be0de6e446457853a006/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f70687066756e63742f66756e63742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/phpfunct/funct)[![Quality Score](https://camo.githubusercontent.com/7126baa2fadb4c07a3d6b98939138f7f4858ffd69ff43922bbdb6ad29cba9479/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f70687066756e63742f66756e63742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/phpfunct/funct)[![Total Downloads](https://camo.githubusercontent.com/fba3755c787bc7a4ca7557950cc06af8f6a7928812f3854888115785400e71b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66756e63742f66756e63742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/funct/funct)

[![Email](https://camo.githubusercontent.com/e3e4a46ec999fd7bad8871d0ce2a60123a3b8a79f04c305bfb2b976482bbcfbb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f656d61696c2d617572696d6173406e69656b69732e6c742d626c75652e7376673f7374796c653d666c61742d737175617265)](mailto:aurimas@niekis.lt)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Library](#general)
    - [General](#general)
        - [arrayKeyNotExists](#arraykeynotexistskey-array-array)
        - [false](#falsevalue)
        - [firstValue](#firstvaluevaluea)
        - [firstValueNotEmpty](#firstvaluenotemptyvaluea-valueb)
        - [ifSetOr](#ifsetorvalue-default)
        - [notEmpty](#notemptyvalue)
        - [notInArray](#notinarrayneedle-haystack-strict--null)
        - [notNull](#notnullvalue)
        - [null](#nullvalue)
        - [tempFile](#tempfileprefix--php)
        - [true](#truevalue)
    - [Collection](#collection)
        - [compact](#compactcollection)
        - [countBy](#countbycollection-callback)
        - [every](#everycollection-callable-callback--null)
        - [findWhere](#findwherecollection-value)
        - [first](#firstcollection)
        - [firstN](#firstncollection-n--1)
        - [flatten](#flattencollection-depth--1)
        - [flattenAll](#flattenallcollection)
        - [forEvery](#foreverycollection-callable)
        - [get](#getcollection-key-default--null)
        - [groupBy](#groupbycollection-callback)
        - [initial](#initialcollection-n--1)
        - [intersection](#intersectioncollectionfirst-collectionsecond)
        - [invoke](#invokecollection-callable-callback)
        - [last](#lastcollection)
        - [lastIndexOf](#lastindexofcollection-value)
        - [lastN](#lastncollection-n--1)
        - [maxValue](#maxvaluecollection-callable-callback)
        - [merge](#mergea-b)
        - [minValue](#minvaluecollection-callable-callback)
        - [pairs](#pairscollection)
        - [partition](#partitioncollection-callable-callback)
        - [pluck](#pluckcollection-key)
        - [reject](#rejectcollection-callable-callback)
        - [rest](#restcollection-from--1)
        - [reverse](#reversecollection-preservenumerickeys)
        - [size](#sizecollection-countrecursive)
        - [some](#somecollection-callable-callback--null)
        - [sortBy](#sortbycollection-sortby-sortfunction--asort)
        - [tail](#tailcollection-from--1)
        - [toJson](#tojsoncollection)
        - [union](#unioncollectionfirst-collectionsecond)
        - [unzip](#unzipcollection)
        - [where](#wherecollection-value)
        - [without](#withoutcollection-without)
        - [zip](#zipcollectionfirst-collectionsecond)
    - [String](#string)
        - [between](#betweeninput-left-right)
        - [camelize](#camelizeinput-firstletteruppercase--false)
        - [chompLeft](#chompleftinput-prefix)
        - [chompRight](#chomprightinput-suffix)
        - [classify](#classifystring)
        - [collapseWhitespace](#collapsewhitespaceinput)
        - [contains](#containsinput-substring)
        - [countOccurrences](#countoccurrencesinput-substring)
        - [dasherize](#dasherizestring)
        - [endsWith](#endswithinput-substring)
        - [includes](#includesinput-substring)
        - [isAlpha](#isalphainput)
        - [isAlphaNumeric](#isalphanumericinput)
        - [isLower](#islowerinput-mb--false)
        - [isNumeric](#isnumericinput)
        - [isUpper](#isupperinput-mb--false)
        - [latinize](#latinizeinput)
        - [left](#leftstring-n)
        - [len](#leninput-mb--false)
        - [length](#lengthinput-mb--false)
        - [lines](#linesstring)
        - [lowerCaseFirst](#lowercasefirstinput)
        - [pad](#padstring-length-char---)
        - [padLeft](#padleftinput-length-char---)
        - [padRight](#padrightinput-length-char---)
        - [repeat](#repeatinput-n)
        - [reverse](#reverseinput)
        - [right](#rightstring-n)
        - [slugify](#slugifystring)
        - [startsWith](#startswithinput-substring)
        - [strip](#stripstring-string1)
        - [stripPunctuation](#strippunctuationstring)
        - [swapCase](#swapcasestring-mb--false)
        - [times](#timesinput-n)
        - [titleize](#tosentencearray-delimiter----lastdelimiter---and-)
        - [toSentence](#tosentencearray-delimiter----lastdelimiter---and-)
        - [toSentenceSerial](#tosentenceserialarray-delimiter----lastdelimiter--and-)
        - [toLower](#tolowerinput-mb--false)
        - [toUpper](#toupperinput-mb--false)
        - [truncate](#truncateinput-length-chars--)
        - [underscore](#underscorestring)
        - [upperCaseFirst](#uppercasefirstinput)
    - [Invoke](#invoke)
        - [ifCondition](#ifconditioncallable-callable-methodarguments---condition)
        - [ifIsset](#ifissetcallable-callable-values-key)
        - [ifNotEmpty](#ifnotemptycallable-callable-var)
    - [Object](#object)
        - [toArray](#toarrayobjects-valuemethod-keymethod--null)
        - [assignIfIsset](#assignifissetobject-property-array-key)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)

Requirements
------------

[](#requirements)

- PHP &gt;= 5.5

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

[](#installation)

Via Composer

```
$ composer require funct/funct
```

Usage
-----

[](#usage)

The library consist of five groups: *Collection*, *Invoke*, *Object*, *Strings* and *General*. Each group has it's own namespace suffix (Only *General* uses root namespace).

To include all group functions just include root namespace at the top of the file:

```
use Funct;
```

For single group functions you have two options. One is to include root namespace and call directly with full namespace for e.g.:

```
use Funct;

Funct\Strings\classify('hello world');
```

or to include only single group for e.g.:

```
use Funct\Strings;

Strings\classify('hello world');
```

If you are using PHP &gt;=5.6 you can include only single function. For e.g.:

```
use function Funct\Strings\classify;

classify('hello world');
```

General
-------

[](#general)

### arrayKeyNotExists($key, array $array)

[](#arraykeynotexistskey-array-array)

Checks if the given key or index exists in the array

```
Funct\arrayKeyNotExists(2, [1, 2]); // => true
Funct\arrayKeyNotExists(1, [1, 2]); // => false
```

### false($value)

[](#falsevalue)

Returns true if value is false

```
Funct\false(false); // => true
Funct\false(true); // => false
```

### firstValue($valueA)

[](#firstvaluevaluea)

Returns a first non null value from function arguments

```
Funct\firstValue('foo_bar'); // => 'foo_bar'
Funct\firstValue(null, 'foo_bar'); // => 'foo_bar'
Funct\firstValue(null, null, 'foo_bar'); // => 'foo_bar'
```

### firstValueNotEmpty($valueA, $valueB)

[](#firstvaluenotemptyvaluea-valueb)

Returns a first not empty value from function arguments

```
Funct\firstValueNotEmpty('foo_bar'); // => 'foo_bar'
Funct\firstValueNotEmpty('', 'foo_bar'); // => 'foo_bar'
Funct\firstValueNotEmpty('', null, 'foo_bar'); // => 'foo_bar'
```

### ifSetOr($value, $default)

[](#ifsetorvalue-default)

Return the first param if isset or the second one or null if it doesn't

```
$bar = 'bar';
Funct\ifSetOr($foo); // => 'NULL'
Funct\ifSetOr($foo, 'foo_bar'); // => 'foo_bar'
Funct\ifSetOr($bar, 'foo_bar'); // => 'bar' ($bar value)
```

### notEmpty($value)

[](#notemptyvalue)

Returns true if value is not empty

```
Funct\notEmpty('fooBar'); // => true
Funct\notEmpty(''); // => false
```

### notInArray($needle, $haystack, $strict = null)

[](#notinarrayneedle-haystack-strict--null)

Checks if needle is not in array

```
Funct\notInArray(3, [0, 1, 2]); // => true
Funct\notInArray(2, [0, 1, 2]); // => false
```

### notNull($value)

[](#notnullvalue)

Returns true if value is not null

```
Funct\notNull('fooBar'); // => true
Funct\notNull(null); // => false
```

### null($value)

[](#nullvalue)

Returns true if value is null

```
Funct\null(null); // => true
Funct\null('fooBar'); // => false
```

### tempFile($prefix = 'php')

[](#tempfileprefix--php)

Generates temp file on systems temp folder with prefix

```
Funct\tempFile('php'); // => /tmp/someFile.php
```

### true($value)

[](#truevalue)

Returns true if value is true

```
Funct\true(true); // => true
Funct\true(false); // => false
```

Collection
----------

[](#collection)

### compact($collection)

[](#compactcollection)

Returns a copy of the array with all falsy values removed

```
Collection\compact([0, 1, false, 2, '', 3]); // => [1, 2, 3]
```

### countBy($collection, $callback)

[](#countbycollection-callback)

Sorts a array into groups and returns a count for the number of objects in each group. Similar to groupBy, but instead of returning a array of values, returns a count for the number of values in that group

```
Collection\countBy(
	[1, 2, 3, 4, 5],
	function ($value) {
		return $value % 2 == 0 ? 'even': 'odd';
	}
); // => ['odd' => 3, 'even' => 2]
Collection\countBy(
    [
        ['color' => 'red', 'title' => 'Foo'],
        ['color' => 'red', 'title' => 'Foo'],
        ['color' => 'red', 'title' => 'Foo'],
        ['color' => 'blue', 'title' => 'Bar'],
        ['color' => 'blue', 'title' => 'Bar']
    ],
    'color'
); // => ['red' => 3, 'blue => 2]
```

### every($collection, callable $callback = null)

[](#everycollection-callable-callback--null)

Returns true if all of the values in the array pass the callback truth test.

```
Collection\every([true, 1, null, 'yes']); // => false
Collection\every([true, 1, 'yes']); // => true
Collection\every(
    [2, 4, 6],
    function ($value) {
        return ($value % 2) === 0;
    }
); // => true
```

### findWhere($collection, $value)

[](#findwherecollection-value)

Looks through the array and returns the first value that matches all of the key-value pairs listed in properties.

```
Collection\findWhere(
    [
        ['title' => 'Book of Fooos', 'author' => 'FooBar', 'year' => 1111],
        ['title' => 'Cymbeline', 'author' => 'Shakespeare', 'year' => 1611],
        ['title' => 'The Tempest', 'author' => 'Shakespeare', 'year' => 1611],
        ['title' => 'Book of Foos Barrrs', 'author' => 'FooBar', 'year' => 2222],
        ['title' => 'Still foooing', 'author' => 'FooBar', 'year' => 3333],
        ['title' => 'Happy Foo', 'author' => 'FooBar', 'year' => 4444],
    ],
    ['author' => 'Shakespeare', 'year' => 1611]
); // => ['title' => 'Cymbeline', 'author' => 'Shakespeare', 'year' => 1611]
```

### first($collection)

[](#firstcollection)

First value of collection

```
Collection\first([1, 2, 3]); // => 1
```

### firstN($collection, $n = 1)

[](#firstncollection-n--1)

```
Collection\firstN([1, 2, 3]); // => [1]
Collection\firstN([1, 2, 3], 2); // => [1, 2]
```

### flatten($collection, $depth = 1)

[](#flattencollection-depth--1)

Flattens a nested array by depth.

```
Collection\flatten(['a', ['b', ['c', ['d']]]]); // => ['a', 'b', ['c', ['d']]]
Collection\flatten(['a', ['b', ['c', ['d']]]], 2); // => ['a', 'b', 'c', ['d']]
Collection\flatten(['a', ['b', ['c', ['d']]]], 3); // => ['a', 'b', 'c', 'd']
```

### flattenAll($collection)

[](#flattenallcollection)

Flattens all arrays to single level

```
Collection\flattenAll(['a', ['b', ['c', ['d']]]]); // => ['a', 'b', 'c', 'd']
```

### forEvery($collection, $callable)

[](#foreverycollection-callable)

Alias of invoke($collection, $callable)

### get($collection, $key, $default = null)

[](#getcollection-key-default--null)

Returns item from collection if exists otherwise null or default value

```
$collection = ['red' => []];

$collection['blue'] = Collection\get($collection, 'blue', []);
$collection['blue'][] = 'Hello World';

Collection\get($collection, 'red', ['empty']);
```

### groupBy($collection, $callback)

[](#groupbycollection-callback)

Splits a collection into sets, grouped by the result of running each value through callback. If callback is a string

```
Collection\groupBy([1.3, 2.1, 2.4], function($num) { return floor($num); }); // => [1 => [1.3], 2 => [2.1, 2.4]]
Collection\groupBy(['one', 'two', 'three'], 'strlen'); // => [3 => ["one", "two"], 5 => ["three"]]
```

### initial($collection, $n = 1)

[](#initialcollection-n--1)

Returns everything but the last entry of the array. Especially useful on the arguments object. Pass n to exclude the

```
Collection\initial([5, 4, 3, 2, 1]); // => [5, 4, 3, 2]
Collection\initial([5, 4, 3, 2, 1], 2); // => [5, 4, 3]
```

### intersection($collectionFirst, $collectionSecond)

[](#intersectioncollectionfirst-collectionsecond)

Computes the list of values that are the intersection of all the arrays. Each value in the result is present in each

```
Collection\intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); // => [1, 2]
```

### invoke($collection, callable $callback)

[](#invokecollection-callable-callback)

Invokes callback on each value in the list. Any extra arguments passed will be forwarded on to the method invocation.

```
Collection\invoke(['a', 'b', 'c'], 'strtoupper'); // => ['A', 'B', 'C']
```

### last($collection)

[](#lastcollection)

Returns last element of array

```
Collection\last([1, 2, 3]); // => 3
```

### lastIndexOf($collection, $value)

[](#lastindexofcollection-value)

Returns the index of the last occurrence of value in the array, or false if value is not present

```
Collecton\lastIndexOf([1, 2, 3, 1, 2, 3], 2); // => 4
```

### lastN($collection, $n = 1)

[](#lastncollection-n--1)

Returns the last element of an array. Passing n will return the last n elements of the array.

```
Collection\lastN([1, 2, 3]); // => [3]
Collection\lastN([1, 2, 3], 2); // => [2, 3]
```

### maxValue($collection, callable $callback)

[](#maxvaluecollection-callable-callback)

Returns the maximum value in collection using callback method

```
Collection\maxValue(
    [
        10 => [
            'title' => 'a',
            'size'  => 1
        ],
        20 => [
            'title' => 'b',
            'size'  => 2
        ],
        30 => [
            'title' => 'c',
            'size'  => 3
        ]
    ],
    function ($item) {
        return $item['size'];
    }
); // => [
     'title' => 'c',
     'size'  => 3
 ]
```

### merge(&amp;$a, $b)

[](#mergea-b)

Merges all arrays to first array

```
$array = [1, 2];
Collection\merge($array, [3, 4], [5, 6]);

$array // => [1, 2, 3, 4, 5, 6];
```

### minValue($collection, callable $callback)

[](#minvaluecollection-callable-callback)

Returns the minimum value in collection using callback method

```
Collection\minValue(
    [
        10 => [
            'title' => 'a',
            'size'  => 1
        ],
        20 => [
            'title' => 'b',
            'size'  => 2
        ],
        30 => [
            'title' => 'c',
            'size'  => 3
        ]
    ],
    function ($item) {
        return $item['size'];
    }
); // => [
     'title' => 'a',
     'size'  => 1
 ]
```

### pairs($collection)

[](#pairscollection)

Convert an array into a list of \[key, value\] pairs.

```
Collection\pairs([1, 2, 3]); // => [[0, 1], [1, 2], [2, 3]]
```

### partition($collection, callable $callback)

[](#partitioncollection-callable-callback)

Split array into two arrays: one whose elements all satisfy callback and one whose elements all do not satisfy

```
Collection\partition([1, 2, 3, 4, 5, 6, 7, 8, 9], function ($num) { return $num % 2 === 0; }); // => [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]]
```

### pluck($collection, $key)

[](#pluckcollection-key)

Extract single property from array of arrays

```
Collection\pluck(
    [
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]
    ],
    0
); // => [1, 4, 7]
```

### reject($collection, callable $callback)

[](#rejectcollection-callable-callback)

Returns the values in array without the elements that the truth test callback passes. The opposite of array\_filter.

```
Collection\reject([1, 2, 3, 4, 5, 6], function($num) { return $num % 2 == 0; }); // => [1, 3, 5]
```

### rest($collection, $from = 1)

[](#restcollection-from--1)

Returns the rest of the elements in an array. Pass an from to return the values of the array from that index onward.

```
Collection\rest([5, 4, 3, 2, 1]); // => [4, 3, 2, 1]
```

### reverse($collection, $preserveNumericKeys)

[](#reversecollection-preservenumerickeys)

Reverses an array.

```
Collection\reverse(['a', 'b', 'c']); // ['c', 'b', 'a']

Collection\reverse(['php', 7.0, ['green', 'red']], true); // [2 => [0 => 'green', 1 => 'red'], 1 => 7.0, 0 => 'php']
```

### size($collection, $countRecursive)

[](#sizecollection-countrecursive)

Computes the size of a collection, i.e., count all elements in a collection

```
Collection\size(['a', 'b', 'c']); // 3
Collection\size(['a', 'b', 'c', ['d', 'e']], true); // 6
```

### some($collection, callable $callback = null)

[](#somecollection-callable-callback--null)

Returns true if any of the values in the array pass the callback truth test.

```
Collection\some([null, 0, 'yes', false]); // => true
```

### sortBy($collection, $sortBy, $sortFunction = 'asort')

[](#sortbycollection-sortby-sortfunction--asort)

Returns a sorted array by callback function which should return value to which sort

```
Collection\sortBy([1, 2, 3, 4, 5, 6], function ($num) { return sin($num); }); // => [5, 4, 6, 3, 1, 2]
```

### tail($collection, $from = 1)

[](#tailcollection-from--1)

Alias of rest($collection, $from = 1)

### toJson($collection)

[](#tojsoncollection)

Returns the JSON representation of a collection

```
Collection\toJson(['a' => 1, 'b' => 2, 'c' => 3]); // {"a":1,"b":2,"c":3}
```

### union($collectionFirst, $collectionSecond)

[](#unioncollectionfirst-collectionsecond)

Computes the union of the passed-in arrays: the list of unique items, in order, that are present in one or more of

```
Collection\union([1, 2, 3], [101, 2, 1, 10], [2, 1]); // => [1, 2, 3, 101, 10]
```

### unzip($collection)

[](#unzipcollection)

The opposite of zip. Given a number of arrays, returns a series of new arrays, the first of which contains all of

```
Collection\unzip([['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]]); // => ["moe", 30, true], ["larry", 40, false], ["curly", 50, false]
```

### where($collection, $value)

[](#wherecollection-value)

Looks through each value in the array, returning an array of all the values that contain all of the key-value pairs

```
Collection\findWhere(
    [
        ['title' => 'Book of Fooos', 'author' => 'FooBar', 'year' => 1111],
        ['title' => 'Cymbeline', 'author' => 'Shakespeare', 'year' => 1611],
        ['title' => 'The Tempest', 'author' => 'Shakespeare', 'year' => 1611],
        ['title' => 'Book of Foos Barrrs', 'author' => 'FooBar', 'year' => 2222],
        ['title' => 'Still foooing', 'author' => 'FooBar', 'year' => 3333],
        ['title' => 'Happy Foo', 'author' => 'FooBar', 'year' => 4444],
    ],
    ['author' => 'Shakespeare', 'year' => 1611]
); // => [
    1 => ['title' => 'Cymbeline', 'author' => 'Shakespeare', 'year' => 1611],
    2 => ['title' => 'The Tempest', 'author' => 'Shakespeare', 'year' => 1611]
]
```

### without($collection, $without)

[](#withoutcollection-without)

Returns a copy of the array with all instances of the values removed.

```
Collection\without([1, 2, 1, 0, 3, 1, 4], 0, 1); // => [2, 3, 4]
```

### zip($collectionFirst, $collectionSecond)

[](#zipcollectionfirst-collectionsecond)

Merges together the values of each of the arrays with the values at the corresponding position.

```
Collection\zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); // => [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
```

String
------

[](#string)

### between($input, $left, $right)

[](#betweeninput-left-right)

Extracts the string between two substrings

```
Strings\between('foo', '', ''); // => 'foo'
Strings\between('foo', '', ''); // => 'foo'
Strings\between('foo', '', ''); // => 'foo'
Strings\between('foo', '', ''); // => ''
Strings\between('Some strings } are very {weird}, dont you think?', '{', '}'); // => 'weird'
Strings\between('This is a test string', 'test'); // => ' string'
Strings\between('This is a test string', '', 'test'); // => 'This is a '
```

### camelize($input, $firstLetterUppercase = false)

[](#camelizeinput-firstletteruppercase--false)

Camelizes string

```
Strings\camelize('data_rate'); //'dataRate'
Strings\camelize('background-color'); //'backgroundColor'
Strings\camelize('-moz-something'); //'mozSomething'
Strings\camelize('_car_speed_'); //'carSpeed'
Strings\camelize('yes_we_can'); //'yesWeCan'Strings\camelize(
```

### chompLeft($input, $prefix)

[](#chompleftinput-prefix)

Removes prefix from start of string

```
Strings\chompLeft('foobar', 'foo'); //'bar'
Strings\chompLeft('foobar', 'bar'); //'foobar'
```

### chompRight($input, $suffix)

[](#chomprightinput-suffix)

Removes suffix from end of string

```
Strings\chompRight('foobar', 'bar'); // => 'foo'
Strings\chompRight('foobar', 'foo'); // => 'foobar'
```

### classify($string)

[](#classifystring)

Converts string to camelized class name. First letter is always upper case

```
Strings\classify('className'); // => ClassName
```

### collapseWhitespace($input)

[](#collapsewhitespaceinput)

Collapse multiple spaces

```
Strings\collapseWhitespace("  String   \t libraries are   \n\n\t fun\n!  "); // => 'String libraries are fun !'
```

### contains($input, $substring)

[](#containsinput-substring)

Check if string contains substring

```
Strings\contains('PHP is one of the best languages!', 'one'); // => true
```

### countOccurrences($input, $substring)

[](#countoccurrencesinput-substring)

Count the occurrences of substring in string

```
Strings\countOccurrences('AN likes to program. AN does not play in the NBA.', "AN"); // => 2
Strings\countOccurrences('Does not exist.', "Flying Spaghetti Monster"); // => 0
Strings\countOccurrences('Does not exist.', "Bigfoot");  // => 0
Strings\countOccurrences('PHP is fun, therefore Node.js is fun', "fun"); // => 2
Strings\countOccurrences('funfunfun', "fun"); // => 3
```

### dasherize($string)

[](#dasherizestring)

Converts hyphens and camel casing to dashes

```
Strings\dasherize('dataRate'); // => 'data-rate'
Strings\dasherize('CarSpeed'); // => 'car-speed'
Strings\dasherize('yesWeCan'); // => 'yes-we-can'
Strings\dasherize('backgroundColor'); // => 'background-color'
```

### endsWith($input, $substring)

[](#endswithinput-substring)

Check if string ends with substring

```
Strings\endsWith("hello jon", 'jon'); // => true
```

### includes($input, $substring)

[](#includesinput-substring)

Alias of contains

### isAlpha($input)

[](#isalphainput)

Check if string contains only letters

```
Strings\isAlpha("afaf"); // => true
Strings\isAlpha('fdafaf3'); // => false
Strings\isAlpha('dfdf--dfd'); // => false
```

### isAlphaNumeric($input)

[](#isalphanumericinput)

Check if string contains only alphanumeric

```
Strings\isAlphaNumeric("afaf35353afaf"); // => true
Strings\isAlphaNumeric("FFFF99fff"); // => true
Strings\isAlphaNumeric("99"); // => true
Strings\isAlphaNumeric("afff"); // => true
Strings\isAlphaNumeric("Infinity"); // => true
Strings\isAlphaNumeric("-Infinity"); // => false
Strings\isAlphaNumeric("-33"); // => false
Strings\isAlphaNumeric("aaff.."); // => false
```

### isLower($input, $mb = false)

[](#islowerinput-mb--false)

Checks if letters in given string are all lowercase.

```
Strings\isLower('a'); // => true
Strings\isLower('z'); // => true
Strings\isLower('B'); // => false
Strings\isLower('hiAN'); // => true
Strings\isLower('hi AN'); // => false
Strings\isLower('HelLO'); // => false
```

### isNumeric($input)

[](#isnumericinput)

Check if string contains only digits

```
Strings\isNumeric("3"); // => true
Strings\isNumeric("34.22"); // => false
Strings\isNumeric("-22.33"); // => false
Strings\isNumeric("NaN"); // => false
Strings\isNumeric("Infinity"); // => false
Strings\isNumeric("-Infinity"); // => false
Strings\isNumeric("AN"); // => false
Strings\isNumeric("-5"); // => false
Strings\isNumeric("000992424242"); // => true
```

### isUpper($input, $mb = false)

[](#isupperinput-mb--false)

Checks if letters in given string are all uppercase.

```
Strings\isUpper('a'); // => false
Strings\isUpper('z');  // => false
Strings\isUpper('B'); // => true
Strings\isUpper('HIAN'); // => true
Strings\isUpper('HI AN'); // => false
Strings\isUpper('HelLO'); // => true
```

### latinize($input)

[](#latinizeinput)

Remove accents from latin characters

```
Strings\latinize('crème brûlée'); // => 'creme brulee'
```

### left($string, $n)

[](#leftstring-n)

Return the substring denoted by n positive left-most characters

```
Strings\left('My name is AN', 2); // => 'My'
Strings\left('Hi', 0); // => ''
Strings\left('My name is AN', -2); // => 'AN', same as right(2)
```

### len($input, $mb = false)

[](#leninput-mb--false)

Alias of length($input, $mb = false);

### length($input, $mb = false)

[](#lengthinput-mb--false)

Get string length.

```
Strings\length('rod'); // 3
Strings\length('marçal'); // 7
Strings\length('marçal', true); // 6
```

### lines($string)

[](#linesstring)

Returns an array with the lines. Cross-platform compatible

```
Strings\lines("My name is AN\nPHP is my fav language\r\nWhat is your fav language?"); // => [ 'My name is AN',
                                                                                                     'PHP is my fav language',
                                                                                                     'What is your fav language?' ]
```

### lowerCaseFirst($input)

[](#lowercasefirstinput)

Converts string first char to lowercase

```
Strings\lowerCaseFirst('HelloWorld'); // => 'helloWorld
```

### pad($string, $length, $char = ' ')

[](#padstring-length-char---)

Pads the string in the center with specified character. char may be a string or a number, defaults is a space

```
Strings\pad('hello', 5); // 'hello'
Strings\pad('hello', 10); // '   hello  '
Strings\pad('hey', 7); // '  hey  '
Strings\pad('hey', 5); // ' hey '
Strings\pad('hey', 4); // ' hey'
Strings\pad('hey', 7, '-');// '--hey--'
```

### padLeft($input, $length, $char = ' ')

[](#padleftinput-length-char---)

Left pads the string

```
Strings\padLeft('hello', 5); // => 'hello'
Strings\padLeft('hello', 10); // => '     hello'
Strings\padLeft('hello', 7); // => '  hello'
Strings\padLeft('hello', 6); // => ' hello'
Strings\padLeft('hello', 10, '.'); // => '.....hello'
```

### padRight($input, $length, $char = ' ')

[](#padrightinput-length-char---)

Right pads the string

```
Strings\padRight('hello', 5); // => 'hello'
Strings\padRight('hello', 10); // => 'hello     '
Strings\padRight('hello', 7); // => 'hello  '
Strings\padRight('hello', 6); // => 'hello '
Strings\padRight('hello', 10, '.'); // => 'hello.....'
```

### repeat($input, $n)

[](#repeatinput-n)

Alias times($input, $n)

### reverse($input)

[](#reverseinput)

Reverses a string

```
Strings\reverse('hello world'); // => dlrow olleh
```

### right($string, $n)

[](#rightstring-n)

Return the substring denoted by n positive right-most characters

```
Strings\right('I AM CRAZY', 2); // => 'ZY'
Strings\right('Does it work?  ', 4); // => 'k?  '
Strings\right('Hi', 0); // => ''
Strings\right('My name is AN', -2); // => 'My', same as left(2)
```

### slugify($string)

[](#slugifystring)

Converts the text into a valid url slug. Removes accents from Latin characters

```
Strings\slugify('Global Thermonuclear Warfare'); // => 'global-thermonuclear-warfare'
Strings\slugify('Crème brûlée'); // => 'creme-brulee'
```

### startsWith($input, $substring)

[](#startswithinput-substring)

Check if string starts with substring

```
Strings\startsWith("AN is a software engineer", "AN"); // => true
Strings\startsWith('wants to change the world', "politicians"); // => false
```

### strip($string, $string1)

[](#stripstring-string1)

Returns a new string with all occurrences of \[string1\],\[string2\],... removed.

```
Strings\strip(' 1 2 3--__--4 5 6-7__8__9--0', ' ', '_', '-'); // => '1234567890'
Strings\strip('can words also be stripped out?', 'words', 'also', 'be'); // => 'can    stripped out?'
```

### stripPunctuation($string)

[](#strippunctuationstring)

Strip all of the punctuation

```
Strings\stripPunctuation('My, st[ring] *full* of %punct)'); // => 'My string full of punct'
```

### swapCase($string, $mb = false)

[](#swapcasestring-mb--false)

Returns a case swapped version of the string

```
Strings\swapCase('RoD eLIas'); // rOd EliAS
```

### times($input, $n)

[](#timesinput-n)

Repeat the string n times

```
Strings\times(' ', 3); // => '   '
Strings\times('*', 3); // => '***'
```

### titleize($string, array $ignore = \[\])

[](#titleizestring-array-ignore--)

Creates a title version of the string. Capitalizes all the words and replaces some characters in the string to

```
Strings\titleize('hello world'); // => 'Hello World'
```

### toSentence($array, $delimiter = ', ', $lastDelimiter = ' and ')

[](#tosentencearray-delimiter----lastdelimiter---and-)

Join an array into a human readable sentence

```
Strings\toSentence(["A", "B", "C"]); // => "A, B and C";
Strings\toSentence(["A", "B", "C"], ", ", " ir "); // => "A, B ir C";
```

### toSentenceSerial($array, $delimiter = ', ', $lastDelimiter = 'and ')

[](#tosentenceserialarray-delimiter----lastdelimiter--and-)

The same as string\_to\_sentence, but adjusts delimeters to use Serial comma)

```
Strings\toSentenceSerial(["A", "B"]); // => "A and B"
Strings\toSentenceSerial(["A", "B", "C"]); // => "A, B, and C"
Strings\toSentenceSerial(["A", "B", "C"], ", ", " unt "); // => "jQuery, Mootools, unt Prototype"
```

### toLower($input, $mb = false)

[](#tolowerinput-mb--false)

Makes a string lowercase;

```
Strings\toLower('ROD ELIAS'); // rod elias
```

### toUpper($input, $mb = false)

[](#toupperinput-mb--false)

Makes a string uppercase;

```
Strings\toUpper('rod elias'); // ROD ELIAS
```

### truncate($input, $length, $chars = '…')

[](#truncateinput-length-chars--)

Truncate string accounting for word placement and character count

```
Strings\truncate('this is some long text', 3); // => '...'
Strings\truncate('this is some long text', 7); // => 'this is...'
Strings\truncate('this is some long text', 11); // => 'this is...'
Strings\truncate('this is some long text', 12); // => 'this is some...'
Strings\truncate('this is some long text', 11); // => 'this is...'
Strings\truncate('this is some long text', 14, ' read more'); // => 'this is some read more'
```

### underscore($string)

[](#underscorestring)

Converts hyphens and camel casing to underscores

```
Strings\underscore('dataRate'); // => 'data_rate'
Strings\underscore('CarSpeed'); // => 'car_speed'
Strings\underscore('yesWeCan'); // => 'yes_we_can'
```

### upperCaseFirst($input)

[](#uppercasefirstinput)

Converts string first char to uppercase

```
Strings\upperCaseFirst('helloWorld'); // => 'HelloWorld
```

Invoke
------

[](#invoke)

### ifCondition(callable $callable, $methodArguments = \[\], $condition)

[](#ifconditioncallable-callable-methodarguments---condition)

Invoke a method if condition is true

```
Invoke\ifCondition(function () { echo 'Hello World'; }, [], Funct\notEmpty('Hello?')); // => Hello World
```

### ifIsset(callable $callable, $values, $key)

[](#ifissetcallable-callable-values-key)

Invoke a method if value isset

```
Invoke\ifIsset(function () { echo 'Hello World'; }, ['Hello' = > 1000], 'Hello'); // => Hello World
```

### ifNotEmpty(callable $callable, $var)

[](#ifnotemptycallable-callable-var)

Invoke a method if value is not empty

```
Invoke\ifNotEmpty(function () { echo 'Hello World'; }, 'Hello'); // => Hello World
```

Object
------

[](#object)

### toArray($objects, $valueMethod, $keyMethod = null)

[](#toarrayobjects-valuemethod-keymethod--null)

Creates array from objects using valueMethod as value and with/without keyMethod as key

```
Object\toArray($objects, 'getValue', 'getkey'); // => ['key' => 'value']
```

### assignIfIsset($object, $property, $array, $key)

[](#assignifissetobject-property-array-key)

Assign value to object from array if key exists

```
$array = ['bar' => 'foobar'];

Object\assignIfIsset($object, 'foo', $array, 'bar'); // => $object->foo = 'foobar'
```

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

License
-------

[](#license)

Please see [License File](LICENSE) for more information.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community42

Growing community involvement

Maturity69

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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

Recently: every ~791 days

Total

9

Last Release

631d ago

Major Versions

0.2.0 → 1.0.02015-12-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/770bae1f46ac2b4536db820b8642491c25e2e2fd44e761110269e4722679a80d?d=identicon)[aurimasniekis](/maintainers/aurimasniekis)

---

Top Contributors

[![aurimasniekis](https://avatars.githubusercontent.com/u/15481?v=4)](https://github.com/aurimasniekis "aurimasniekis (8 commits)")[![LucantisSwann](https://avatars.githubusercontent.com/u/15977539?v=4)](https://github.com/LucantisSwann "LucantisSwann (7 commits)")[![hansott](https://avatars.githubusercontent.com/u/3886384?v=4)](https://github.com/hansott "hansott (3 commits)")[![iselldonuts](https://avatars.githubusercontent.com/u/37897386?v=4)](https://github.com/iselldonuts "iselldonuts (3 commits)")[![jremes-foss](https://avatars.githubusercontent.com/u/4118513?v=4)](https://github.com/jremes-foss "jremes-foss (3 commits)")[![mokevnin](https://avatars.githubusercontent.com/u/308430?v=4)](https://github.com/mokevnin "mokevnin (3 commits)")[![taponomarev](https://avatars.githubusercontent.com/u/76124633?v=4)](https://github.com/taponomarev "taponomarev (1 commits)")[![artengin](https://avatars.githubusercontent.com/u/152782500?v=4)](https://github.com/artengin "artengin (1 commits)")[![cjean-fr](https://avatars.githubusercontent.com/u/87385?v=4)](https://github.com/cjean-fr "cjean-fr (1 commits)")[![dfridrich](https://avatars.githubusercontent.com/u/3758421?v=4)](https://github.com/dfridrich "dfridrich (1 commits)")[![digitalroll](https://avatars.githubusercontent.com/u/103197016?v=4)](https://github.com/digitalroll "digitalroll (1 commits)")[![alekgit](https://avatars.githubusercontent.com/u/24228837?v=4)](https://github.com/alekgit "alekgit (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/funct-funct/health.svg)

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

PHPackages © 2026

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