SkillAgentSearch skills...

Funct

A PHP library with commonly used code blocks

Install / Use

/learn @phpfunct/Funct
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Funct

A PHP library with commonly used code blocks for faster development

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

Latest Version Software License Build Status Code Coverage Quality Score Total Downloads

Email

Requirements

  • PHP >= 5.5

Installation

Via Composer

$ composer require funct/funct

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 >=5.6 you can include only single function. For e.g.:

use function Funct\Strings\classify;

classify('hello world');

General

arrayKeyNotExists($key, 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)

Returns true if value is false

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

firstValue($valueA)

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)

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)

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)

Returns true if value is not empty

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

notInArray($needle, $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)

Returns true if value is not null

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

null($value)

Returns true if value is null

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

tempFile($prefix = 'php')

Generates temp file on systems temp folder with prefix

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

true($value)

Returns true if value is true

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

Collection

compact($collection)

Returns a copy of the array with all falsy values removed

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

countBy($collection, $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)

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;
    }
View on GitHub
GitHub Stars605
CategoryDevelopment
Updated9d ago
Forks40

Languages

PHP

Security Score

95/100

Audited on Mar 27, 2026

No findings