Documentation

Core_Array
in package

Array helper

Tags
subpackage

Core

version
7.x
author

Hostmake LLC

copyright

© 2005-2024 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru

Table of Contents

Methods

array2jsObject()  : string
Convert array to the literal notation for the JS-object, e.g. array('foo' => 'bar', 'baz' => true) to string 'foo': 'bar', 'baz': true
changeKey()  : mixed
Change $oldKey to the $newKey with $newValue (optional)
combine()  : array<string|int, mixed>
Combine Arrays
end()  : mixed
Get the value of the last element
findByKey()  : null|mixed
Find value by key in multidimensional array
first()  : mixed
Get the value of the first element
get()  : mixed
Get value for $key in array $array. If value does not exist will return defaultValue.
getCookie()  : mixed
Get value for $key in array $_COOKIE. If value does not exist will return defaultValue.
getFiles()  : mixed
Get value for $key in array $_FILES. If value does not exist will return defaultValue.
getGet()  : mixed
Get value for $key in array $_GET. If value does not exist will return defaultValue.
getPost()  : mixed
Get value for $key in array $_POST. If value does not exist will return defaultValue.
getRequest()  : mixed
Get value for $key in array $_REQUEST. If value does not exist will return defaultValue.
getSession()  : mixed
Get value for $key in array $_SESSION. If value does not exist will return defaultValue.
implode()  : string
Join multi-level array elements with a string
isList()  : bool
Checks whether a given array is a list and values are scalar
randomShuffle()  : array<string|int, mixed>
Перемешивание элементов массива. Если передан hash - перемешивание будет осуществлено в соответствии с этим значением.
randomValue()  : mixed
Возвращает случайное значение из массива
set()  : mixed
Set value $defaultValue for $key in array $array.
toInt()  : mixed
Convert all values of array to int
union()  : array<string|int, mixed>
Union arrays $array1 and $array2. If $array1 is not array will return $array2
_filter()  : mixed
Filter Value

Methods

array2jsObject()

Convert array to the literal notation for the JS-object, e.g. array('foo' => 'bar', 'baz' => true) to string 'foo': 'bar', 'baz': true

public static array2jsObject(array<string|int, mixed> $array) : string
Parameters
$array : array<string|int, mixed>

The array of strings to implode.

Return values
string

changeKey()

Change $oldKey to the $newKey with $newValue (optional)

public static changeKey(array<string|int, mixed> $array, mixed $oldKey, mixed $newKey[, mixed $newValue = NULL ]) : mixed
Parameters
$array : array<string|int, mixed>
$oldKey : mixed

Old Key

$newKey : mixed

New Key

$newValue : mixed = NULL

New Value, if NULL the old value is used

combine()

Combine Arrays

public static combine(array<string|int, mixed> $aArray[, int $_iIndex = 0 ]) : array<string|int, mixed>
Parameters
$aArray : array<string|int, mixed>
$_iIndex : int = 0

index

array('aaa', 'bbb', 'ccc'), 22 => array(111, 222, 333) ); $aReturn = Core_Array::combine($arrays); print_r($aReturn); ?>
Return values
array<string|int, mixed>

end()

Get the value of the last element

public static end(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

массив

findByKey()

Find value by key in multidimensional array

public static findByKey(array<string|int, mixed> $array, mixed $key) : null|mixed
Parameters
$array : array<string|int, mixed>
$key : mixed
Return values
null|mixed

Null or value

first()

Get the value of the first element

public static first(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

массив

get()

Get value for $key in array $array. If value does not exist will return defaultValue.

public static get(array<string|int, mixed> $array, string $key[, mixed $defaultValue = NULL ][, mixed $filter = NULL ]) : mixed
$array = array('fruit' => 'apple', 'baz' => 'quz'); // Return 'apple' $value = Core_Array::get($array, 'fruit');

// Return NULL $value = Core_Array::get($array, 'foo');

// Return 'bar' $value = Core_Array::get($array, 'foo', 'bar');

Parameters
$array : array<string|int, mixed>

array

$key : string

key

$defaultValue : mixed = NULL

default value

$filter : mixed = NULL

filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim', 'array', 'filterVarInt', 'filterVarFloat', 'filterVarBoolean'

getCookie()

Get value for $key in array $_COOKIE. If value does not exist will return defaultValue.

public static getCookie(string $key[, mixed $defaultValue = NULL ][, mixed $filter = NULL ]) : mixed
// Return value for 'foo' or NULL if $key does not exist $value = Core_Array::getCookie('foo'); // Return value for 'foo' or 'bar' if $key does not exist $value = Core_Array::getCookie('foo', 'bar');
Parameters
$key : string

key

$defaultValue : mixed = NULL

default value

$filter : mixed = NULL

filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim', 'array'

getFiles()

Get value for $key in array $_FILES. If value does not exist will return defaultValue.

public static getFiles( $key[,  $defaultValue = NULL ]) : mixed
Parameters
$key :

key

$defaultValue : = NULL

default value // Return value for 'foo' or NULL if $key does not exist $value = Core_Array::getFiles('foo'); // Return value for 'foo' or array() if $key does not exist $value = Core_Array::getFiles('foo', array());

getGet()

Get value for $key in array $_GET. If value does not exist will return defaultValue.

public static getGet(string $key[, mixed $defaultValue = NULL ][, mixed $filter = NULL ]) : mixed
// Return value for 'foo' or NULL if $key does not exist $value = Core_Array::getGet('foo'); // Return value for 'foo' or 'bar' if $key does not exist $value = Core_Array::getGet('foo', 'bar');
Parameters
$key : string

key

$defaultValue : mixed = NULL

default value

$filter : mixed = NULL

filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim', 'array'

getPost()

Get value for $key in array $_POST. If value does not exist will return defaultValue.

public static getPost( $key[,  $defaultValue = NULL ][, mixed $filter = NULL ]) : mixed
Parameters
$key :

key

$defaultValue : = NULL

default value

$filter : mixed = NULL

filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim', 'array' // Return value for 'foo' or NULL if $key does not exist $value = Core_Array::getPost('foo'); // Return value for 'foo' or 'bar' if $key does not exist $value = Core_Array::getPost('foo', 'bar'); // Return value for 'foo' or 'bar' if $key does not exist $value = Core_Array::getPost('foo', 'bar', 'trim');

getRequest()

Get value for $key in array $_REQUEST. If value does not exist will return defaultValue.

public static getRequest( $key[,  $defaultValue = NULL ][, mixed $filter = NULL ]) : mixed
Parameters
$key :

key

$defaultValue : = NULL

default value

$filter : mixed = NULL

filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim', 'array' // Return value for 'foo' or NULL if $key does not exist $value = Core_Array::getRequest('foo'); // Return value for 'foo' or 'bar' if $key does not exist $value = Core_Array::getRequest('foo', 'bar');

getSession()

Get value for $key in array $_SESSION. If value does not exist will return defaultValue.

public static getSession(string $key[, mixed $defaultValue = NULL ][, mixed $filter = NULL ]) : mixed
// Return value for 'foo' or NULL if $key does not exist $value = Core_Array::getSession('foo'); // Return value for 'foo' or 'bar' if $key does not exist $value = Core_Array::getSession('foo', 'bar');
Parameters
$key : string

key

$defaultValue : mixed = NULL

default value

$filter : mixed = NULL

filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim', 'array'

implode()

Join multi-level array elements with a string

public static implode(string $glue, array<string|int, mixed> $array) : string
Parameters
$glue : string
$array : array<string|int, mixed>

The array of strings to implode.

Return values
string

isList()

Checks whether a given array is a list and values are scalar

public static isList(array<string|int, mixed> $array) : bool
Parameters
$array : array<string|int, mixed>
Return values
bool

randomShuffle()

Перемешивание элементов массива. Если передан hash - перемешивание будет осуществлено в соответствии с этим значением.

public static randomShuffle(array<string|int, mixed> $array[, int $hash = NULL ]) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>

массив

$hash : int = NULL

числовое значение

Return values
array<string|int, mixed>

перемешанный массив

randomValue()

Возвращает случайное значение из массива

public static randomValue(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

массив

set()

Set value $defaultValue for $key in array $array.

public static set(array<string|int, mixed> &$array, mixed $key[, mixed $defaultValue = NULL ]) : mixed
Parameters
$array : array<string|int, mixed>

array

$key : mixed

key

$defaultValue : mixed = NULL

value

$array = array('fruit' => 'apple'); Core_Array::set($array, 'baz', 'quz');

toInt()

Convert all values of array to int

public static toInt( $array) : mixed
Parameters
$array :

array $array = (1, 2, '3', 'a' => '321') $array = Core_Array::toInt($array); var_dump($array);

union()

Union arrays $array1 and $array2. If $array1 is not array will return $array2

public static union(mixed $array1, array<string|int, mixed> $array2) : array<string|int, mixed>
Parameters
$array1 : mixed
$array2 : array<string|int, mixed>
Return values
array<string|int, mixed>

_filter()

Filter Value

protected static _filter(mixed $value, mixed $filter) : mixed
Parameters
$value : mixed
$filter : mixed

filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim', 'array', 'filterVarInt', 'filterVarFloat', 'filterVarBoolean'


        
On this page

Search results