RSI helpers  0.1
RSI helpers
Record Class Reference

Record (array) helpers. More...

Static Public Member Functions

static explode ($array, $delimiter=null, $separator=null)
 Enhanced explode. More...
 
static implode ($array, $delimiter=null, $separator=null)
 Enhanced implode. More...
 
static exists ($array, $key)
 Checks if a key exists in an array. More...
 
static get ($array, $key, $default=null)
 Get a value from an array. More...
 
static iget ($array, $key, $default=null)
 Get a value from an array in a case insensitive way. More...
 
static set (&$array, $key, $value)
 Set a value of an array. More...
 
static add (&$array, $key, $value=null)
 Add a value to an array if the key does not already exist. More...
 
static delete (&$array, $key)
 Delete a (nested) key from an array. More...
 
static flatten ($array, $key_glue=null, $key_prefix=null)
 Flattens a multi-dimensional array. More...
 
static expand ($array, $key_glue)
 Brings a flattend array back to its multi-dimensional form. More...
 
static value ($array, $index=0, $default=null)
 Get the n-th value from an array. More...
 
static key ($array, $index=0)
 Get the n-th key from an array. More...
 
static assoc ($array)
 Determine if an array is associative (that is, no ascending numerical key). More...
 
static splice ($array, $offset, $length=0, $replace=null)
 Splice with keys. More...
 
static merge (... $arrays)
 Merge arrays while preserving (duplicate) key sequence. More...
 
static resize ($array, $length, $filler=null)
 Set the length of an array. More...
 
static combine ($keys, $values, $filler=null)
 Creates an array by using one array for keys and another for its values. More...
 
static isearch ($array, $value)
 Searches the array for a given value and returns the first corresponding key if successful. More...
 
static prefix ($array, $prefix)
 Add a prefix to all members of an array. More...
 
static prefixKey ($array, $prefix)
 Add a prefix to all keys of an array. More...
 
static changeKey ($array, $keys, $keep=true)
 Change the keys of an array. More...
 
static mergeKey ($array, $key_name=null, $value_name=null)
 Merge the key and value of an assoc.array into a record. More...
 
static column ($array, $column)
 Return the values from a single column in the input array. More...
 
static group ($array, $column)
 Group records by a column. More...
 
static shuffle ($array)
 Shuffle an array. More...
 
static average ($array)
 Calculate the average of an array. More...
 
static deviation ($array, &$average=null)
 Calculate the mean average deviation of an array. More...
 
static select ($array, $keys)
 Return specific keys from an array. More...
 
static sort ($array, $options=null, $key=false)
 Sort an array. More...
 
static ranges ($array)
 Retrieve numerical ranges from an array. More...
 
static groupByLetter ($array, $length=1, $case_sensitive=false)
 Group a list of strings by its first letter(s). More...
 
static groupByStart ($array, $max=25, $other=0, $min=true, $word='\\W+\\w *')
 Group a list of strings by its most common start. More...
 

Detailed Description

Record (array) helpers.

Definition at line 8 of file Record.php.

Member Function Documentation

◆ add()

static add ( $array,
  $key,
  $value = null 
)
static

Add a value to an array if the key does not already exist.

Parameters
array$arrayArray to store the value in.
string | array$keyKey to store the value at. An array indicates a nested key. If the array is ['foo' => ['bar' => 'acme']], then the nested key for the 'acme' value will be ['foo','bar'].
mixed$value

Definition at line 126 of file Record.php.

◆ assoc()

static assoc (   $array)
static

Determine if an array is associative (that is, no ascending numerical key).

Parameters
array$array
Returns
bool True if the array is associative.

Definition at line 195 of file Record.php.

◆ average()

static average (   $array)
static

Calculate the average of an array.

Parameters
array$arrayArray with numerical values.
Returns
float Average value (false on empty array).

Definition at line 366 of file Record.php.

◆ changeKey()

static changeKey (   $array,
  $keys,
  $keep = true 
)
static

Change the keys of an array.

Parameters
array$arraySource array.
array$keysKey = old key, value = new key.
bool$keepIf true, entries in the source array for which there is nog new key defined, will be kept in the result (with their original key).

Definition at line 296 of file Record.php.

◆ column()

static column (   $array,
  $column 
)
static

Return the values from a single column in the input array.

Basicly PHP's array_column, but then retaining key association.

Parameters
array$arrayA multi-dimensional array (record set) from which to pull a column of values.
string$columnThe column of values to return.
Returns
array Returns an array of values representing a single column from the input array.

Definition at line 329 of file Record.php.

◆ combine()

static combine (   $keys,
  $values,
  $filler = null 
)
static

Creates an array by using one array for keys and another for its values.

Basicly PHP's array_combine, but then without the same length restriction.

Parameters
array$keysArray of keys.
array$valuesArray of values.
mixed$fillerFiller to use if array of values is shorter than keys.
Returns
array Combined array.

Definition at line 251 of file Record.php.

◆ delete()

static delete ( $array,
  $key 
)
static

Delete a (nested) key from an array.

Parameters
array$arrayArray to delete the key from.
string | array$keyKey to delete. An array indicates a nested key.

Definition at line 137 of file Record.php.

◆ deviation()

static deviation (   $array,
$average = null 
)
static

Calculate the mean average deviation of an array.

Parameters
array$arrayArray with numerical values.
float$averageAvarage value of array.
Returns
float Mean average deviation (false on empty array).

Definition at line 375 of file Record.php.

◆ exists()

static exists (   $array,
  $key 
)
static

Checks if a key exists in an array.

Parameters
array$arrayArray to look in.
string | array$keyKey to look at. An array indicates a nested key. If the array is ['foo' => ['bar' => 'acme']], then the nested key for the 'acme' value will be ['foo','bar'].
Returns
bool True if the key exists.

Definition at line 53 of file Record.php.

◆ expand()

static expand (   $array,
  $key_glue 
)
static

Brings a flattend array back to its multi-dimensional form.

Parameters
array$arrayOne dimensional array.
string$key_glueGlue with which the keys are combined.
Returns
array Multi-dimensional array.

Definition at line 166 of file Record.php.

◆ explode()

static explode (   $array,
  $delimiter = null,
  $separator = null 
)
static

Enhanced explode.

Parameters
mixed$arrayValue to turn into an array.
string$delimiterDelimiter in case of a string.
string$separatorKey-value separator.
Returns
array

Definition at line 17 of file Record.php.

◆ flatten()

static flatten (   $array,
  $key_glue = null,
  $key_prefix = null 
)
static

Flattens a multi-dimensional array.

Parameters
array$arrayArray to flatten.
string$key_glueKey to combine the keys with (sequential, numerical keys if empty).
string$key_prefixPrefix for the key.
Returns
array One dimensional array.

Definition at line 153 of file Record.php.

◆ get()

static get (   $array,
  $key,
  $default = null 
)
static

Get a value from an array.

Parameters
array$arrayArray to look in.
string | array$keyKey to look at. An array indicates a nested key. If the array is ['foo' => ['bar' => 'acme']], then the nested key for the 'acme' value will be ['foo','bar'].
mixed$defaultDefault value if the key does not exist.
Returns
mixed Found value, or default value if the key does not exist.

Definition at line 70 of file Record.php.

◆ group()

static group (   $array,
  $column 
)
static

Group records by a column.

Parameters
array$arrayA multi-dimensional array (record set).
string$columnThe column to group by.
Returns
array Records (value; maintaining key association) grouped by column (key).

Definition at line 340 of file Record.php.

◆ groupByLetter()

static groupByLetter (   $array,
  $length = 1,
  $case_sensitive = false 
)
static

Group a list of strings by its first letter(s).

Parameters
array$arrayArray with strings.
int$lengthNumber of characters to group by.
bool$case_sensitiveUse case sensitivity for grouping.
Returns
array Key = letter(s), value = array with strings (and keys).

Definition at line 439 of file Record.php.

◆ groupByStart()

static groupByStart (   $array,
  $max = 25,
  $other = 0,
  $min = true,
  $word = '\\W+\\w*' 
)
static

Group a list of strings by its most common start.

Parameters
array$arrayArray with strings.
int$maxMaximum number of groups.
int | bool$otherNumber of keys from the smallest groups to group into one single group (empty key) (true = half of average group size).
int | bool$minMinimum group size (true = 10% of average group size).
string$wordWord mask (regex).
Returns
array Group (key = common part) with keys from string list (value).

Definition at line 459 of file Record.php.

◆ iget()

static iget (   $array,
  $key,
  $default = null 
)
static

Get a value from an array in a case insensitive way.

See also
get()
Parameters
array$arrayArray to look in.
string | array$keyKey to look at (case insensitive). An array indicates a nested key. If the array is ['foo' => ['bar' => 'acme']], then the nested key for the 'acme' value will be ['foo','bar'].
mixed$defaultDefault value if the key does not exist.
Returns
mixed Found value, or default value if the key does not exist.

Definition at line 85 of file Record.php.

◆ implode()

static implode (   $array,
  $delimiter = null,
  $separator = null 
)
static

Enhanced implode.

Parameters
mixed$arrayArray to turn into a string
string$delimiterDelimiter.
string$separatorKey-value separator.
Returns
string

Definition at line 40 of file Record.php.

◆ isearch()

static isearch (   $array,
  $value 
)
static

Searches the array for a given value and returns the first corresponding key if successful.

Basicly PHP's array_search, but case insensitive.

Parameters
array$arrayArray with values.
mixed$valueValue to look for.
Returns
mixed Key if found, otherwise false.

Definition at line 261 of file Record.php.

◆ key()

static key (   $array,
  $index = 0 
)
static

Get the n-th key from an array.

Parameters
array$arrayArray to get key from.
int$indexKey index (negative = start from end).
Returns
mixed Found key, false if not existing.

Definition at line 187 of file Record.php.

◆ merge()

static merge (   $arrays)
static

Merge arrays while preserving (duplicate) key sequence.

E.g. ['a' => 5,'b' => 7,'d' => 3] + ['b' => 4,'c' => 2,'d' => 1] returns ['a' => 5,'b' => 4,'c' => 2,'d' => 1].

Parameters
array$arrays,...input array(s).
Returns
array

Definition at line 216 of file Record.php.

◆ mergeKey()

static mergeKey (   $array,
  $key_name = null,
  $value_name = null 
)
static

Merge the key and value of an assoc.array into a record.

Parameters
array$arrayAssoc.array.
string$key_nameName under which the key is added to the record. If empty the key is not added.
string$value_nameName under which the value is added to the record. If empty, and the value is an array, this array is merged with the record. Otherwise the value is not added.
Returns
array Array of records (key is preserved).

Definition at line 311 of file Record.php.

◆ prefix()

static prefix (   $array,
  $prefix 
)
static

Add a prefix to all members of an array.

Parameters
array$arrayArray with values.
string$prefixPrefix to add.
Returns
array Prefixed array.

Definition at line 273 of file Record.php.

◆ prefixKey()

static prefixKey (   $array,
  $prefix 
)
static

Add a prefix to all keys of an array.

Parameters
array$arrayArray with values.
string$prefixPrefix to add.
Returns
array Prefixed array.

Definition at line 284 of file Record.php.

◆ ranges()

static ranges (   $array)
static

Retrieve numerical ranges from an array.

Parameters
array$arrayArray with numbers.
Returns
array Key = start of range, value = end of range.

Definition at line 415 of file Record.php.

◆ resize()

static resize (   $array,
  $length,
  $filler = null 
)
static

Set the length of an array.

Parameters
array$arrayInput array.
int$lengthDesired length.
mixed$fillerValue for new possible entries.
Returns
array Input array with its length chopped or extended.

Definition at line 240 of file Record.php.

◆ select()

static select (   $array,
  $keys 
)
static

Return specific keys from an array.

Parameters
array$arrayArray to select from.
array$keysKeys to select.
Returns
array

Definition at line 387 of file Record.php.

◆ set()

static set ( $array,
  $key,
  $value 
)
static

Set a value of an array.

If the key does not exist it will be created. With a nested key, sub-array will also be created.

Parameters
array$arrayArray to store the value in.
string | array$keyKey to store the value at. An array indicates a nested key. If the array is ['foo' => ['bar' => 'acme']], then the nested key for the 'acme' value will be ['foo','bar'].
mixed$value

Definition at line 110 of file Record.php.

◆ shuffle()

static shuffle (   $array)
static

Shuffle an array.

Basicly PHP's shuffle, but then retaining key association (and not altering the input array).

Parameters
array$arrayInput array.
Returns
array Shuffled array.

Definition at line 354 of file Record.php.

◆ sort()

static sort (   $array,
  $options = null,
  $key = false 
)
static

Sort an array.

Parameters
array$arrayArray to sort.
callable | int$optionsCallback function for sorting or sorting flags.
bool$keySort by key.
Returns
array Sorted array.

Definition at line 399 of file Record.php.

◆ splice()

static splice (   $array,
  $offset,
  $length = 0,
  $replace = null 
)
static

Splice with keys.

Parameters
array$arrayInput array.
int$offsetWhere to start (negative = from end).
int$lengthLength of part to remove.
array$replaceArray to replace removed part with.
Returns
array

Definition at line 206 of file Record.php.

◆ value()

static value (   $array,
  $index = 0,
  $default = null 
)
static

Get the n-th value from an array.

Parameters
array$arrayArray to get value from.
int$indexValue index (negative = start from end).
mixed$defaultDefault value if the index does not exist.
Returns
mixed

Definition at line 178 of file Record.php.


The documentation for this class was generated from the following file: