Arrays Library



( ZN >= 2.0.0 )

It is a library that is created to perform operations on arrays. While the use of some methods is parallel to procedural use, others involve differences in usage. The purpose of creating this library is not to classify functions only. These functions are compiled and made easier and useful functions.

 

# Methods


Array force ( Array $ array , Callable $ callback )
Array forceKeys ( Array $ array , Callable $ callback )
Array forceValues ​​( Array $ array , Callable $ callback )
Array addFirst ( Array $ array , Mixed $ element )
Array addLast ( Array $ arrayMixed $ element )
Array getFirst ( Array $ array , Int $ count = 1 , Bool $ preserveKey = false )
Array getLast ( Array $ array , Int $ count = 1 , Bool $ preserveKey = false )
Array removeKey ( Array $ arrayMixed $ keys )
Array removeValue ( Array $ arrayMixed $ values )
Array remove ( Array $ array , $ keysMixed $ values )
Array removeFirst ( Array $ array , Int $ count = 1 )
Array removeLast ( Array $ array , Int $ count = 1 )
Array deleteElement ( Array $ arrayMixed $ object )
Array casing ( Array $ array , String $ type = 'lower' , String $ keyval = 'all' )
Array lowerKeys ( Array $ array )
Array titleKeys ( Array $ array )
Array upperKeys ( Array $ array )
Array lowerValues ​​( Array $ array )
Array titleValues ​​( Array $ array )
Array upperValues ​​( Array $ array )
Array <span style=">lowerCase ("> lowerCase ( Array lowerCase(">$ array )
Array titleCase ( Array $ array )
Array upperCase ( Array $ array )
Mixed each ( Array $ array , Callable $ callable )
Array exclude / excluding ( Array $ array , Array $ excluding
Array include / including ( Array $ array , Array $ includi
Array keyval ( Array $ array , String $ keyval = 'value' )
Array value ( Array $ array )
Array key ( Array $ array )
Array values ​​( Array $ array )
Array keys ( Array $ array )
Array multikey ( Array $ array , String $ keySplit = '|' )
Int length ( Array $ data )
Array apportion ( array $ data , Int $ portioncount = 1 , Boolean $ preservekeys = false )
Array combine ( Array $ keys , Array $ values )
Array countSameValues ​​( Array $ array , String $ key = NULL )
Array flip / transform ( Array $ array )
Array implementCallback / map ( Array ... $ args )
Array recursiveMerge ( Array ... $ args )
Array merge ( Array ... $ args )
Array intersect ( Array ... $ args )
Array intersectKey ( Array ... $ args )
Array reverse ( Array $ array , Bool $ preserveKeys = false )
float product ( Array $ array )
float sum ( Array $ array )
Array random ( Array $ array , Int $ countRequest )
Mixed search ( Array $ array , $ element , Bool $ strict = false )
Bool valueExists ( Array $ array , $ element , Bool $ strict = false )
Bool valueExistsInsensitive ( Array $ arrayMixed $ element , Bool $ strict = false )
Bool keyExists ( Array $ arrayMixed $ key )
Array section ( Array $ array , Int $ start = 0 , Int $ len = NULL , Bool $ preserve = false )
Array resection ( Array $ array , Int $ start = 0 , Int $ len = NULL,  Mixed $ new = NULL )
Array deleteRecurrent ( Array $ array , String $ flags = 'string' )
Array series ( Int $ start , Int $ end , Int $ step = 1 )
Array column ( Array $ arrayMixed $ columnKeyMixed $ indexKey = NULL )
Array order ( Array $ array , String $ type = NULL , String $ flags = 'regular' )
Array sort ( Array $ array , String $ flag = 'regular' )
Array descending ( Array $ array , String $ flag = 'regular' )
Array ascending ( Array $ array , String $ flag = 'regular' )
Array ascendingKey ( Array $ array , String $ flag = 'regular' )
Array descendingKey ( Array $ array , String $ flag = 'regular' )
Array userAssocSort ( Array $ array , String $ flag = 'regular' )
Array userKeySort ( Array $ array , String $ flag = 'regular' )
Array userSort ( Array $ array , String $ flag = 'regular' )
Array insensitiveSort ( Array $ array )
Array naturalSort ( Array $ array )
Array shuffle ( Array $ array )
Array unidimensional ( array $ array , boolean $ preservekey = true )

 

# Force ( ZN >= 4.3.2 )


It was created to call back array keys and their values.

Parameters

Array $ array Related series.
Mixed $ Callable The function to be applied.
return Array

Use of

$arrays = ['a' => 'A', 'b' => 'B'];

$array = Arrays::force($arrays, function($data)
{
    return suffix($data, '+');
});

output($array);
a + => string 'A + (length = 4 ),
b + => string ' B + ' (length = 4 )

 

# ForceKeys ( ZN >= 4.3.2 )


It was created to call back array keys.

Parameters

Array $ array Related series.
Mixed $ Callable The function to be applied.
return Array

Use of

$arrays = ['a' => 'A', 'b' => 'B'];

$array = Arrays::forceKeys($arrays, function($data)
{
    return suffix($data, '+');
});

output($array);
a + => string 'A' (length = 3 )
b + => string 'B' (length = 3 )

 

# ForceValues ( ZN >= 4.3.2 )


It was created to apply a callback to array values.

Parameters

Array $ array Related series.
Mixed $ Callable The function to be applied.
return Array

Use of

$arrays = ['a' => 'A', 'b' => 'B'];

$array = Arrays::forceValues($arrays, function($data)
{
    return suffix($data, '+');
});

output($array);
a => string 'A + (length = 4 )
b => string ' B + ' (length = 4 )

 

# AddFirst ( ZN >= 3.0.0 )


Used to add elements to the index.

Parameters

Array $ array Related series.
Mixed $ data The new value or values ​​to add.
return Array

Use of

$data = ['example' => 'Example'];

$data = Arrays::addFirst($data, 'newElement');
$data = Arrays::addFirst($data, ['firstElement' => 'First Element']);

output($data);
firstelement => string "First Element ' (length = 15 ) ,
0 => string ' newElement ' (length = 12 ) ,
example => string ' example ' (length = 9 )

 

# AddLast ( ZN >= 3.0.0 )


Used to add elements to the end of the array.

Parameters

Array $ array Related series.
Mixed $ data The new value or values ​​to add.
return Array

Use of

$data = ['example' => 'Example'];

$data = Arrays::addLast($data, 'newElement');
$data = Arrays::addLast($data, 
[
    'lastElement'    => 'Last Element', 
    'lastestElement' => 'Lastest Element'
]);

output($data);
example => string 'example' (length = 9 ) ,
0 => string 'newElement' (length = 12 ) ,
lastelement => string 'Last Element' (length = 14 ) ,
lastestelement => string 'Lastest Element' (length = 17 )

 

# GetFirst ( ZN >= 3.0.0 )


Used to get elements from the beginning of the index.

Parameters

Array $ array Related series.
Int $ count = 1 How many elements are selected is specified.
Bool $ preserveKey = false It is specified that the index indexes will not be preserved.
return Mixed

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output(Arrays::getFirst($data));
output(Arrays::getFirst($data, 2));
Foo
foo => string 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 )

 

# GetLast ( ZN >= 3.0.0 )


Used to retrieve elements from the end of the array.

Parameters

Array $ array Related series.
Int $ count = 1 How many elements are selected is specified.
Bool $ preserveKey = false It is specified that the index indexes will not be preserved.
return Mixed

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output(Arrays::getLast($data));
output(Arrays::getLast($data, 2));
Some
bars => string 'bar' (length = 5 ) ,
base => string 'base' (length = 5 )

 

# RemoveKey ( ZN> = 3.0.0 )


It is used to delete element by array key.

Parameters

Array $ array Related series.
Mixed $ keys Which key belongs will be deleted.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output(Arrays::removeKey($data, 'bar'));
output('-----------------------------------');
output(Arrays::removeKey($data, ['foo', 'baz']));
foo => string 'Foo' (length = 5 ) ,
baz => string 'Base' (length = 5 ) ,

------------------------ -----------
bar => string 'Bar' (length = 5 )

 

# RemoveValue ( ZN >= 3.0.0 )


Used to delete elements by array value.

Parameters

Array $ array Related series.
Mixed $ keys Which values ​​will be deleted.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output(Arrays::removeValue($data, 'Bar'));
output('-----------------------------------');
output(Arrays::removeValue($data, ['Foo', 'Baz']));
foo => string 'Foo' (length = 5 ) ,
baz => string 'Base' (length = 5 ) ,

------------------------ -----------
bar => string 'Bar' (length = 5 )

 

# Remove ( ZN> = 3.0.0 )


Used to delete elements by array key and value. You can use removeKey () and removeValue () methods at the same time.

Parameters

Array $ array Related series.
Mixed $ keys Which keys or keys will be deleted.
Mixed $ values Which values ​​or values ​​will be deleted.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::remove($data, 'bar', ['Foo', 'Baz']));
zoo => string 'Zoo' (length = 5 )

 

# RemoveFirst ( ZN >= 3.0.0 )


Used to delete elements from the beginning of the index.

Parameters

Array $ array Related series.
Int $ count = 1 How many elements will be deleted.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::removeFirst($data, 1));
output('-----------------------------------');
output(Arrays::removeFirst($data, 2));
bar => string 'bar' (length = 5 ) ,
base => string 'base' (length = 5 ) ,
zoom => string 'Zoom' (length = 5 ) ,

----------- ------------------------
baz => string 'Baz' (length = 5 ) ,
zoo => string 'Zoo' (length = 5 )

 

# RemoveLast ( ZN> = 3.0.0 )


Used to delete an element at the end of the index.

Parameters

Array $ array Related series.
Int $ count = 1 How many elements will be deleted.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::removeLast($data, 1));
output('-----------------------------------');
output(Arrays::removeLast($data, 2));
foo => string 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 ) ,
base => string 'base' (length = 5 ) ,

----------- (length = 5 ) , bar => string 'Bar' (length = 5 ) ------------------------
foo => string 'Foo'

 

# DeleteElement ( ZN> = 2.0.0 )


Used to delete elements from the array. The delete function of this method is slightly different from the others.

Parameters

Array $ array Related series.
Mixed $ object Values ​​and values ​​to delete.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::deleteElement($data, 'Foo'));
output('-----------------------------------');
output(Arrays::deleteElement($data, ['Foo', 'Bar']));
output('-----------------------------------');
output(Arrays::deleteElement($data, ['bar' => 'Baz', 'zoo' => 'Zoo']));
bar => string 'bar' (length = 5 ) ,
base => string 'base' (length = 5 ) ,
zoom => string 'Zoom' (length = 5 ) ,

----------- ------------------------
base => string 'base' (length = 5 ) ,
zoom => string 'Zoom' (length = 5 ) ,

-----------------------------------
foo => String 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 ) ,
 

 

# Casing ( ZN >= 1.0.0 )


Used to convert uppercase and lowercase letters in array elements.

Parameters

Array $ array Related series.
String $ type = 'lower' Conversion type.
Options lower , upper , title
String $ keyval = 'all' Field of rotation applied. So it's only the keys, the values ​​or all of them.
Options all , key , value
return Array

Use of

output(Arrays::casing($data, 'upper'));          // Keys, Values Upper
output('-----------------------------------');
output(Arrays::casing($data, 'upper', 'key'));   // Only Keys Upper
output('-----------------------------------');
output(Arrays::casing($data, 'upper', 'value')); // Only Values Upper
FOO => string 'FOO' (length = 5 ) ,
BAR => string 'bar' (length = 5 ) ,
BASE => string 'base' (length = 5 ) ,
ZOO => string 'ZOOM' (length = 5 ) ,

-----------------------------------
FOO => string 'Foo' (length = 5 ) ,
BAR => string 'Bar' (Length = 5 ) ,
BASE => string 'base' (length = 5 ) ,
ZOO => string 'Zoom' (length = 5 ) ,

------------------ -----------------
foo => string 'fOO' (length = 5 ) ,
bar => string 'BAR' (length = 5 ) ,
base => string 'bASE' (length = 5 ),
zoo => string 'ZOO' (length = 5 )

 

# LowerKeys ( ZN >= 3.0.0 )


Converts array keys to lower case.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::lowerKeys($data));
foo => string 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 ) ,
base => string 'base' (length = 5 ) ,
zoom => string 'Zoom' (length = 5 )

 

# TitleKeys ( ZN> = 3.0.0 )


It only capitalizes the initials of array keys.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::titleKeys($data));
Foo => string 'foo' (length = 5 ) ,
Bar => string 'bar' (length = 5 ) ,
Base => string 'base' (length = 5 ) ,
Zoom => string 'Zoom' (length = 5 )

 

# UpperKeys ( ZN >= 3.0.0 )


Convert array keys to uppercase.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::upperKeys($data));
FOO => string 'foo' (length = 5 ) ,
BAR => string 'bar' (length = 5 ) ,
BASE => string 'base' (length = 5 ) ,
ZOOM => string 'Zoom' (length = 5 )

 

# LowerValues ( ZN >= 3.0.0 )


Converts array values ​​to lowercase.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::lowerValues($data));
foo => string 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 ) ,
base => string 'base' (length = 5 ) ,
zoom => string 'zoom' (length = 5 )

 

# TitleValues ( ZN >= 3.0.0 )


It only converts the initials of array values ​​to uppercase.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::titleValues($data));
foo => string 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 ) ,
base => string 'base' (length = 5 ) ,
zoom => string 'Zoom' (length = 5 )

 

# UpperValues ( ZN >= 3.0.0 )


Converts array values ​​to uppercase.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'zoo' => 'Zoo'];

output(Arrays::upperValues($data));
foo => string 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 ) ,
base => string 'base' (length = 5 ) ,
zoom => string 'Zoom' (length = 5 )

 

# LowerCase ( ZN> = 2.0.0 )


The array turns key and values ​​into lower case.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar'];

output(Arrays::lowerCase($data));
foo => string 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 )

 

# TitleCase ( ZN> = 2.0.0 )


It converts the first letter of the array key and values ​​to uppercase.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar'];

output(Arrays::titleCase($data));
Foo => string 'foo' (length = 5 ) ,
Bar => string 'bar' (length = 5 )

 

# UpperCase ( ZN >= 2.0.0 )


The array turns key and values ​​into upper case.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar'];

output(Arrays::upperCase($data));
FOO => string 'FOO' (length = 5 ) ,
BAR => string 'BAR' (length = 5 )

 

# Each ( ZN> = 3.1.2 )


Used to loop array keys and values.

Parameters

Array $ array Related series.
callable $ Callable The function to be executed.
return Mixed

Use of

Arrays::each($data, function($value, $key)
{
    \Output::writeLine('{0} - {1}', [$key, $value]);
});
foo - Foo
bar - Bar 

 

# Exclude / Excluding ( ZN> = 4.0.0 )


It is used to ignore unwanted elements in the array.

Parameters

Array $ array Related series.
Array $ Exclude Items to be ignored. To ignore, the value or key of the desired element can be used.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output( Arrays::exclude($data, ['foo', 'Baz']) );
bar => string 'Bar' (length = 5 )

 

# Include / Including ( ZN> = 4.0.0 )


It is used to get the desired elements in the array and ignore the others.

Parameters

Array $ array Related series.
Array $ Exclude No numbers will not element. The value or key of the desired element can be used to ignore.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output( Arrays::include($data, ['foo', 'Baz']) );
foo => string 'foo' (length = 5 ) ,
base => string 'base' (length = 5 )

 

# Keyval ( ZN >= 1.0.0 )


A sequence containing key value pairs is used to retrieve only keys or values.

Parameters

Array $ array Related series.
String $ type = 'value' Used to retrieve the keys / values ​​or values ​​/ values contained in the array .
Options value , key , values , keys
return Mixed

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

\Output::writeLine( Arrays::keyval($data) );
\Output::writeLine( Arrays::keyval($data, 'key') );
output( Arrays::keyval($data, 'values') );
output( Arrays::keyval($data, 'keys') );
Foo
foo
0 => string 'foo' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
2 => string 'base' (length = 5 ) ,

0 => string 'foo' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
2 => string 'base' (length= 5 )

 

# Value ( ZN >= 2.0.0 )


Gets the first value of the index.

Parameters

Array $ array Related series.
return Mixed

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

\Output::writeLine( Arrays::value($data) );
foo

 

# Key ( ZN >= 2.0.0 )


Gets the key of the first value of the index.

Parameters

Array $ array Related series.
return Mixed

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

\Output::writeLine( Arrays::key($data) );
foo 

 

# Values ( ZN> = 2.0.0 )


Gets the value of the index.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output( Arrays::values($data) );
0 => string 'foo' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
2 => string 'base' (length = 5 )

 

# Keys ( ZN >= 2.0.0 )


Gets the keys to the directory.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output( Arrays::keys($data) );
0 => string 'foo' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
2 => string 'base' (length = 5 )

 

# Multikey ( ZN >= 2.0.0 )


This method is used if several different array keys are used to hold the same value.

Parameters

Array $ array Related series.
String $ keySplit = '|' Key separator.
return Array

Use of

$data = ['foo|zoo|bar' => 'Foo'];

output( Arrays::multikey($data) );
foo => string 'foo' (length = 5 ) ,
zoom => string 'foo' (length = 5 ) ,
bar => string 'foo' (length = 5 )

 

# ObjectData ( ZN >= 2.0.0 )


Array JSON is used to convert the string. It is in the Json :: encode () method that undertakes this task .

Parameters

Array $ array Related series.
return String

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

write( Arrays::objectData($data) );
{ "Foo": "foo", "bar", "bar", "base": "Base"} 

 

# Length ( ZN >= 3.0.0 )


Gives knowledge of how many members the directory has.

Parameters

Array $ array Related series.
return Int

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

write( Arrays::length($data) );
3

 

# Apportion ( ZN >= 3.0.0 )


It is used to divide the sequence into a specified number of chapters.

Parameters

Array $ array Related series.
Int $ portionCount = 1 It is specified that the pieces will be separated.
Bool $ preserveKey = false The array keys will not be preserved after the operation.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output( Arrays::apportion($data, 2) );
0 => array
(
        0 => string 'foo' (length = 5 ) ,
        1 => string 'bar' (length = 5 ) ,
),
1 => array
(
        0 => string 'base' (length = 5 ) ,
)

 

# Combine ( ZN >= 3.0.0 )


It is used to combine the values ​​of 2 different indexes into the key and value pairs.

Parameters

Array $ array Related series.
Array $ otherarray The other array to join.
return Array

Use of

$data      = ['foo', 'bar'];
$otherData = ['Foo', 'Bar'];

output( Arrays::combine($data, $otherData) );
foo => string 'foo' (length = 5 ) ,
bar => string 'bar' (length = 5 )

 

# CountSameValues ( ZN >= 3.0.0 )


It is used to find out the number of repetitive elements in the array.

Parameters

Array $ array Related series.
String $ key = NULL Which element repeats
return Int

Use of

$data = ['foo', 'bar', 'baz', 'foo', 'foo'];

write( Arrays::countSameValues($data, 'foo') );
3

 

# Transform / Flip ( ZN >= 3.0.0 )


Used to replace the values ​​of the index with the keys.

Parameters

Array $ array Related series.
return Array

Use of

$data = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output( Arrays::transform($data) );
Foo => string 'foo' (length = 5 ) ,
Bar => string 'bar' (length = 5 ) ,
Base => string 'base' (length = 5 )

 

# ImplementCallback / Map ( ZN> = 3.0.0 )


Used to apply methods or functions to array elements.

Parameters

callable $ CallBack The function to be applied.
Array $ Array ... Related series.
return Array

Use of

$data  = ['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'];

output( Arrays::implementCallback('strtoupper', $data) );
foo => string 'FOO' (length = 5 ) ,
bar => string 'BAR' (length = 5 ) ,
base => string 'BASE' (length = 5 )
 

# RecursiveMerge ( ZN >= 3.0.0 )


Creates a new sequence by adding two or more sequences in succession.

Parameters

Array $ Array ... Related series.
return Array

Use of

$data   = ['foo', 'bar' => ['Bar', 'BAR']];
$data2  = ['baz', 'zoo'];

output( Arrays::recursiveMerge($data, $data2) );
0 => string 'foo' (length = 5 ) ,
bar => array
(
        0 => string 'bar' (length = 5 ) ,
        1 => string 'BAR' (length = 5 ) ,
),
1 => string 'base' (length = 5 ) ,
2 => string 'zoo' (length = 5 )

 

# Merge ( ZN >= 3.0.0 )


Creates a new array by concatenating the specified arrays.

Parameters

Array $ Array ... Related series.
return Array

Use of

$data   = ['foo', 'bar'];
$data2  = ['baz', 'zoo'];

output( Arrays::merge($data, $data2) );
0 => string 'foo' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
2 => string 'base' (length = 5 ) ,
3 => string 'zoom' (length = 5 )
 

 

# Intersect ( ZN >= 3.0.0 )


Creates a new array by finding the common elements of the specified array.

Parameters

Array $ Array ... Related series.
return Array

Use of

$data   = ['foo', 'bar', 'baz'];
$data2  = ['baz', 'zoo', 'coo'];

output( Arrays::intersect($data, $data2) );
2 => string 'baz' (length = 5 )

 

# Reverse ( ZN >= 3.0.0 )


Order the elements of the array as terest.

Parameters

Array $ array Related series.
Bool $ preserveKeys = false The array keys will not be protected.
return Array

Use of

$data   = ['foo', 'bar', 'baz'];

output( Arrays::reverse($data) );
output( Arrays::reverse($data, true) );
0 => string 'base' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
2 => string 'foo' (length = 5 ) ,

----------- ----------------------
2 => string 'base' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
0 = > string 'foo' (length = 5 )

 

# Product ( ZN> = 3.0.0 )


Calculates the sum of the values ​​in the array.

Parameters

Array $ array Related series.
return float

Use of

$data = [10, 3, 5];

output( Arrays::product($data) );
150

 

# Sum ( ZN >= 3.0.0 )


Calculates the product of the values ​​in the array.

Parameters

Array $ array Related series.
return float

Use of

$data = [10, 3, 5];

output( Arrays::sum($data) );
18

 

# Search ( ZN> = 3.0.0 )


Used to search through the array. If the element is found in the search result, the index value of that element is returned.

Parameters

Array $ array Related series.
Mixed $ element Search value.
Bool $ strict = false Look at the look of your object.
return Mixed

Use of

$data = ['foo', 'bar', 'baz'];

output( Arrays::search($data, 'baz') );
output( Arrays::search($data, 'bar') );
2
1

 

# ValueExists ( ZN >= 3.0.0 )


Used to look up values ​​in an array. If the result is true then false otherwise.

Parameters

Array $ array Related series.
Mixed $ key Key to search.
return Bool

Use of

$data = ['foo', 'bar', 'baz'];

output( Arrays::valueExists($data, 'bar') );
one

 

# KeyExists ( ZN> = 3.0.0 )


Used to search for keys in the array. If the result is true then false otherwise.

Parameters

Array $ array Related series.
Mixed $ key Key to search.
return Bool

Use of

$data = ['foo', 'bar' => 'Bar', 'baz'];

output( Arrays::keyExists($data, 'bar') );
one

 

# Section ( ZN >= 3.0.0 )


It is used to get the cross section from the line.

Parameters

Array $ array Related series.
Int $ start = 0 Starting index.
Int $ length = NULL How many characters will be taken.
Bool $ preserveKeys = NULL The key values ​​will not be preserved or preserved.
return Array

Use of

$data = ['foo', 'bar', 'baz', 'zoo', 'coo'];

output( Arrays::section($data, 2, 2) );
0 => string 'baz' (length = 5 ) ,
1 => string 'zoo' (length = 5 )

 

# Resection ( ZN >= 3.0.0 )


Used to change a particular section of the index.

Parameters

Array $ array Related series.
Int $ start = 0 Starting index.
Int $ length = NULL How many characters will be taken.
Bool $ newElement = NULL New cross section.
return Array

Use of

$data = ['foo', 'bar', 'baz', 'zoo', 'coo'];

output( Arrays::resection($data, 2, 3, ['BAR', 'ZOO']) );
0 => string 'foo' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
2 => string 'bar' (length = 5 ) ,
3 => string 'ZOOM' (length = 5 )

 

# DeleteRecurrent ( ZN >= 3.0.0 )


It is used to delete duplicate elements in the array.

Parameters

Array $ array Related series.
String $ flags = 'string' Form of behavior.
Options string , numeric , regular , localString
return Array

Use of

$data = ['foo', 'bar', 'baz', 'bar', 'bar'];

output( Arrays::deleteRecurrent($data) );
0 => string 'foo' (length = 5 ) ,
1 => string 'bar' (length = 5 ) ,
2 => string 'base' (length = 5 )

 

# Series ( ZN >= 3.0.0 )


Used to create arrays in a certain range.

Parameters

Int $ start Starting index.
Int $ end End mark.
Int $ step = 1 Amount of increase.
return Array

Use of

output( Arrays::series(0, 100, 10) );
0 => integer 0 (length = 1 ) ,
1 => integer 10 (length = 2 ) ,
2 => integer 20 (length = 2 ) ,
3 => integer 30 (length = 2 ) ,
4 => integer 40 ( length = 2 ) ,
5 => integer 50 (length = 2 ),
6 => integer 60 (length = 2 ) ,
7 => integer 70 (length = 2 ) ,
8 => integer 80 (length = 2 ) ,
9 => integer 90 (length = 2 ) ,
10 => integer 100 (length = 3 )

 

# Column ( ZN >= 3.0.0 )


The key returns the values ​​in the string according to the string.

Parameters

Array $ array Related series.
Mixed $ columnKey = 0 The column of values ​​to rotate.
Mixed $ indexKey = NULL The column to be used as the keys of the rotated index.
return Array

Use of

$records =


[
    ['id' => 13, 'firstName' => 'Foo', 'lastName' => 'FOO'],
    ['id' => 29, 'firstName' => 'Bar', 'lastName' => 'BAR']
];

output( Arrays::column($records, 'firstName') );
0 => string 'Foo' (length = 6 ) ,
1 => string 'Bar' (length = 7 )
output( Arrays::column($records, 'firstName', 'id') );
13 => string 'Foo' (length = 6 ) ,
2 9 => string 'Bar' (length = 7 )

 

# Unidimensional ( ZN >= 5.4.5 )


Makes a multi-dimensional complex array one-dimensional. The arrays in the multi-dimensional structure are removed to the top layer.

Parameters

Array $ array Related series.
Bool $ preserveKey = true Do you keep the keys?
return Array

Use of

$array = ['foo', ['bar'], ['baz' => 'xoo']];

output( Arrays::unidimensional($array) );
0   => foo
1   => bar
baz => xoo