Amiro.CMS API Reference
Amiro.Ru / Manual
Loading search...

The AMI_Lib_Array class

• Introduction

Array library.

• Class synopsis

AMI_Lib_Array {
/* Methods */
// Allows to compare arrays containing arrays as elements.
public static diffAssoc ( $aFirst, $aSecond ) returns array;
// Inserts data into array after/before specified position.
public static insert ( $aSource, $aData, int|string $pos, [ bool $after = TRUE ] ) returns array;
// Prepends prefix for each array key.
public static prependKeyPrefix ( $aSource, string $prefix ) returns array;
// Renames key in associative array.
public static renameKey ( &$aArray, string $from, string $to, [ bool $preserve = FALSE ], [ bool $recursive = FALSE ] ) returns void;
// Sort an array by column.
public static sortMultiArray ( &$aArray, int|string $sortCol, [ int $sort = SORT_STRING ], [ int $direction = SORT_ASC ] ) returns void;
// Sort an array by column preserving row keys.
public static sortMultiArrayPreserveKeys ( &$aArray, int|string $sortCol, [ int $sort = SORT_STRING ], [ int $direction = SORT_ASC ] ) returns void;
// Swap two array elements and returns true if swapped.
public static swap ( &$array, int|string $srcIndex, int|string $destIndex ) returns bool;
}
Tags:
since 5.14.4

• Class Methods

// Allows to compare arrays containing arrays as elements.
public static diffAssoc ( $aFirst, $aSecond ) returns array;
  • array $aFirst
    First array
  • array $aSecond
    Second array
// Inserts data into array after/before specified position.
public static insert ( $aSource, $aData, int|string $pos, [ bool $after = TRUE ] ) returns array;
  • array $aSource
    Source array
  • array $aData
    Data to insert
  • int|string $pos
    Position
  • bool $after
    Flag specifying to insert before or after position
// Prepends prefix for each array key.
public static prependKeyPrefix ( $aSource, string $prefix ) returns array;
  • array $aSource
    Source array
  • string $prefix
    Prefix
Tags:
since 5.12.8
// Renames key in associative array.
public static renameKey ( &$aArray, string $from, string $to, [ bool $preserve = FALSE ], [ bool $recursive = FALSE ] ) returns void;
  • array &$aArray
    Array
  • string $from
    Key to raname from
  • string $to
    Key to raname to
  • bool $preserve
    Preserve key order flag, not implemented yet
  • bool $recursive
    Flag specifying to rename recursively
Tags:
todo Preserve key order option
// Sort an array by column.
public static sortMultiArray ( &$aArray, int|string $sortCol, [ int $sort = SORT_STRING ], [ int $direction = SORT_ASC ] ) returns void;
  • array &$aArray
    Array
  • int|string $sortCol
    Sort column
  • int $sort
    Sort type: SORT_STRING|SORT_REGULAR|SORT_NUMERIC
  • int $direction
    Sort direction: SORT_ASC|SORT_DESC
// Sort an array by column preserving row keys.
public static sortMultiArrayPreserveKeys ( &$aArray, int|string $sortCol, [ int $sort = SORT_STRING ], [ int $direction = SORT_ASC ] ) returns void;
  • array &$aArray
    Array
  • int|string $sortCol
    Sort column
  • int $sort
    Sort type: SORT_STRING|SORT_REGULAR|SORT_NUMERIC
  • int $direction
    Sort direction: SORT_ASC|SORT_DESC
// Swap two array elements and returns true if swapped.
public static swap ( &$array, int|string $srcIndex, int|string $destIndex ) returns bool;
  • array &$array
    Array
  • int|string $srcIndex
    Source index
  • int|string $destIndex
    Destination index