Download the PHP package luminovang/array-functions without Composer
On this page you can find all versions of the php package luminovang/array-functions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download luminovang/array-functions
More information about luminovang/array-functions
Files in luminovang/array-functions
Package array-functions
Short Description A backward utility function for array operations supported in PHP 8.1 and later.
License MIT
Informations about the package array-functions
Luminova Array Procedural Functions
A lightweight utility package for array operations offering procedural functions like array_find, array_all, and more. These functions are already supported in PHP 8.1 and later. This package provide backward compatibility for PHP 8.0.
Install via Composer
Recommend installation method:
Include File
You can also use the function in another projects.
Importing the Functions
You can import multiple functions at once using the use function syntax with braces around the function names:
Importing a Specific Function:
To import a specific function, such as array_find, use the following syntax:
Example Usage
Finding an Element in an Array
The array_find function allows you to find the first element in an array that satisfies a given condition specified in a callback.
In this example,
array_findreturns the first element greater than 3, which is4.
Finding the Key of an Element in an Array
The array_find_key function searches for the first key where the corresponding value meets the given condition.
Here,
array_find_keyfinds the key of 'banana', which is1.
Another Example
Find key using str_starts_with.
In this case,
array_find_keyreturns the key'php', where the key starts with'p'.
Checking If All Elements Meet a Condition
The array_all function checks if all elements in the array satisfy the condition defined in the callback.
In this example,
array_allreturnstruebecause all elements in the array are even numbers.
Checking If Any Element Meets a Condition
The array_any function checks if at least one element in the array meets the condition specified in the callback.
In this case,
array_anyreturnstruebecause one element (3) is greater than2.