Download the PHP package belca/support-array without Composer

On this page you can find all versions of the php package belca/support-array. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package support-array

Belca\Support\Arr - PHP helper functions for handling arrays

The documentation is actual for version 1.0.

The Belca\Support\Arr class has functions for handling arrays containing standard data (the data does not use special storage rules). Although you can use them as you like.

Some examples

Read the documentation to know about other functions.

Install

You must have PHP 7.0 and later and Composer.

Install the package. Look at the example:

Use the in your classes.

Now you can use all functions of the package.

Array functions

Arr::concatArray

Arr::concatArray(&$source, $array, $replace = true) : void

Adds new values with new keys to the end of a source array.

If $replace is 'true' then all existing value with same keys will be replaced with new values.

Unlike the array_merge() the function does not create and it does not returns a new array, it works with the source array.

Unlike the array_merge() that adds a new array to the first array when to use integer keys, Arr::concatArray() replaces identical integer keys as if they associative keys.

The function executes $array1 += $array2 or $array2 + $array1 operations in accordance with a given $replace parameter.

Parameters:

Example #1: Adding new values in the array and replacing values with same keys. The array has integer keys.

First 6 values of the soure array were be replaced the new values. Also was added a new value: 12. This was happened because keys of the source array coincided with the second array.

Example #2: Adding new values in the array and replacing values with same keys. The keys of the second array are offset.

In this example we get the necessary result, the function concatenated the new values to the source array. This may sometimes be useful.

In the next example we will be to use an associative array where values that have same keys will be replaced.

Example #3: Adding new values in the array and replacing old values with same keys.

However replacing values of the source array may not always be useful. You may add only new values that are not yet in the source array.

See this example.

Example 4: Adding only new values in the array.

You might sight the function do not returns a result, it process the source array.

See also:

Arr::firstExists

Arr::firstExists(...$values): mixed

Returns the first existing value or returns 'null'.

Arr::firstNotEmpty

Arr::firstNotEmpty(...$values): mixed

Returns the first value which is not empty or returns 'null'.

Arr::isArrayWithIntKeys

Arr::isArrayWithIntKeys(array $array) : boolean

Checks whether integer keys are in an array. Uses for detecting non-associative arrays. Returns 'true' if all keys of the array are integer.

The empty array is not the integer array, because that its keys cannot be detected.

See also:

Arr::isFirstLastWithIntKeys

Arr::isFirstLastWithIntKeys(array $array) : boolean

Checks whether the first value and the last value have integer keys. Returns 'true' if they are integer. Uses for simple detecting non-associative arrays.

The function is analogue isArrayWithIntKeys(), but keys must have some one from types: string keys or integer key.

The empty array is not the integer array, because that its keys cannot be detected.

In comparasion with Arr::isArrayWithIntKeys() (Arr::isIntKeys()), that may scan all values of an array, this function checks only the first and the last keys, that doing more faster.

See also:

Arr::isIntKeys

Arr::isIntKeys(array $array) : boolean

The alias of Arr::isArrayWithIntKeys().

Arr::last

Arr::last(&$array) : mixed

Returns the last item of a given array. The pointer of the position of the array is saving.

Arr::pushArray

Arr::pushArray(&$array, ...$array) : void

Joins values of other arrays to the source array. Values with string keys will be replaced when they equals, values with number keys will be adjoined to the source array.

See the result. 1, 2, 3 values from $array2 were added in the source array, but the source array had these values and were added duplicates.

If you want not same values in an array, then use array_unique() to get only unique values. The function will be apply to all keys, even to string keys, where different keys may keep same values.

See also:

Arr::removeArrays

Arr::removeArrays($array, $resetIndex = false) : array

Removes nested arrays (subarrays) from an array. If $resetIndex is 'true' then resets keys of the array.

Parameters:

Example 1: Removing inner arrays.

In the example in the array were removed all arrays and kept other values.

Sometimes you need to reset keys of an array as shown below.

Example 2: Remove inner arrays and resetting keys the array.

Arr::removeEmpty

Arr::removeEmpty(array $array) : array

Removes each values of an array where the empty value. Uses the function 'empty'. Keys of the array are saving.

Arr::removeEmptyRecurcive

Arr::removeEmptyRecurcive(array $array, boolean $resetIndex = true) : array

Recursively removes the empty values of a multidimensional array. If the function takes not array then it returns an unchanged value.

Parameters:

Example #1. Recursive removing empty values and resetting keys of arrays.

In the example you see that resetting keys were only in arrays with integer keys. So the basic keys of the array and the keys of the $arrar['a3'] value was not changed, and the others keys were reset.

Example 2. Recursive removing empty values without resetting keys

In the example the keys were not changed, because $resetIndex was set as false.

See also:

Arr::removeNotScalar

Arr::removeNotScalar(array $array) : array

Removes each values of an array with the value is 'null' or other values that are not scalar values. Scalar values are those containing an integer, float, string or boolean.

Arr::removeNull

Arr::removeNull(array $array) : array

Removes each values of an array where a value is 'null'. Uses the function 'is_null'. Keys of the array are saving.

Arr::removeNullRecurcive

Arr::removeNullRecurcive(array $array, boolean $resetIndex = true) : array

Recursively removes the null values of a multidimensional array.

Parameters:

Example 1: Removing values with 'null' and resetting keys.

In the example performing resetting keys of the arrays where all keys of an array are integer. So the keys of $array[2] were not changed, but the index of the value was changed.

Example 2: Removing values with 'null' and without resetting keys.

See also:

Arr::trim

Arr::trim(array $array) : array

Trims string values of an array. Keys of the array are saving. The function does not handle nested arrays.

Arr::unset

Arr::unset($array, ...$indexes) : array

Removes values of an array by given keys without changing keys of the array. Returns a new array.

This function may be useful when you need to remove from an array unknown values by knowing their indexes. The same effect may be get using array_filter() or unset(), but this function are more readable and compact.

Arr::unsetByReference

Arr::unsetByReference(array &$array, ...$keys): void

Removes values of an array by given keys. The function do not return a result.

Example 1: Removing values using simple keys

Example 2: Removing values using keys in arrays

See also:


All versions of support-array with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package belca/support-array contains the following files

Loading the files please wait ....