Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

funct

> 编程语言
Open source

A PHP library with commonly used code blocks

603 stars0 likes1 views
WebsiteGitHub

About

A PHP library with commonly used code blocks

A PHP library with commonly used code blocks for faster development

php
Funct\firstValueNotEmpty($a, $b, $c)
  • Requirements
  • Installation
  • Usage
  • Library
    • General
      • arrayKeyNotExists
      • false
      • firstValue
      • firstValueNotEmpty
      • ifSetOr
      • notEmpty
      • notInArray
      • notNull
      • null
      • tempFile
      • true
    • Collection
      • compact
      • countBy
      • every
      • findWhere
      • first
      • firstN
      • flatten
      • flattenAll
      • forEvery
      • get
      • groupBy
      • initial
      • intersection
      • invoke
      • last
      • lastIndexOf
      • lastN
      • maxValue
      • merge
      • minValue
      • pairs
      • partition
      • pluck
      • reject
      • rest
      • reverse
      • size
      • some
      • sortBy
      • tail
      • toJson
      • union
      • unzip
      • where
      • without
      • zip
    • String
      • between
      • camelize
      • chompLeft
      • chompRight
      • classify
      • collapseWhitespace
      • contains
      • countOccurrences
      • dasherize
      • endsWith
      • includes
      • isAlpha
      • isAlphaNumeric
      • isLower
      • isNumeric
      • isUpper
      • latinize
      • left
      • len
      • length
      • lines
      • lowerCaseFirst
      • pad
      • padLeft
      • padRight
      • repeat
      • reverse
      • right
      • slugify
      • startsWith
      • strip
      • stripPunctuation
      • swapCase
      • times
      • titleize
      • toSentence
      • toSentenceSerial
      • toLower
      • toUpper
      • truncate
      • underscore
      • upperCaseFirst
    • Invoke
      • ifCondition
      • ifIsset
      • ifNotEmpty
    • Object
      • toArray
      • assignIfIsset
  • Testing
  • Contributing
  • License

Requirements

  • PHP >= 5.5

Installation

Via Composer

bash
$ 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:

php
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.:

php
use Funct;

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

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

php
use Funct\Strings;

Strings\classify('hello world');

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

php
use function Funct\Strings\classify;

classify('hello world');

General

arrayKeyNotExists($key, array $array)

Checks if the given key or index exists in the array

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

false($value)

Returns true if value is false

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

firstValue($valueA)

Returns a first non null value from function arguments

php
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

php
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

php
$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

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

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

Checks if needle is not in array

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

notNull($value)

Returns true if value is not null

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

null($value)

Returns true if value is null

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

tempFile($prefix = 'php')

Generates temp file on systems temp folder with prefix

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

true($value)

Returns true if value is true

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

Collection

compact($collection)

Returns a copy of the array with all falsy values removed

php
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

php
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.

php
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)

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

…

first($collection)

First value of collection

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

firstN($collection, $n = 1)

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

flatten($collection, $depth = 1)

Flattens a nested array by depth.

php
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)

Flattens all arrays to single level

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

forEvery($collection, $callable)

Alias of invoke($collection, $callable)

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

Returns item from collection if exists otherwise null or default value

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

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

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

groupBy($collection, $callback)

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

php
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)

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

php
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)

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

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

invoke($collection, callable $callback)

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

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

last($collection)

Returns last element of array

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

lastIndexOf($collection, $value)

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

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

lastN($collection, $n = 1)

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

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

maxVal

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言