[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/utilities/src/ -> ArrayHelper.php (summary)

Part of the Joomla Framework Utilities Package

Copyright: Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
License: GNU General Public License version 2 or later; see LICENSE
File Size: 757 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 18 functions

  __construct()
  toInteger()
  toObject()
  toString()
  fromObject()
  arrayFromObject()
  addColumn()
  dropColumn()
  getColumn()
  getValue()
  invert()
  isAssociative()
  pivot()
  sortObjects()
  arrayUnique()
  arraySearch()
  flatten()
  mergeRecursive()

Functions
Functions that are not part of a class:

__construct()   X-Ref
Private constructor to prevent instantiation of this class


toInteger($array, $default = null)   X-Ref
Function to convert array to integer values

param: array      $array    The source array to convert
param: int|array  $default  A default value to assign if $array is not an array
return: array

toObject(array $array, $class = 'stdClass', $recursive = true)   X-Ref
Utility function to map an array to a stdClass object.

param: array    $array      The array to map.
param: string   $class      Name of the class to create
param: boolean  $recursive  Convert also any array inside the main array
return: object

toString(array $array, $innerGlue = '=', $outerGlue = ' ', $keepOuterKey = false)   X-Ref
Utility function to map an array to a string.

param: array    $array         The array to map.
param: string   $innerGlue     The glue (optional, defaults to '=') between the key and the value.
param: string   $outerGlue     The glue (optional, defaults to ' ') between array elements.
param: boolean  $keepOuterKey  True if final key should be kept.
return: string

fromObject($source, $recurse = true, $regex = null)   X-Ref
Utility function to map an object to an array

param: object   $source   The source object
param: boolean  $recurse  True to recurse through multi-level objects
param: string   $regex    An optional regular expression to match on field names
return: array

arrayFromObject($item, $recurse, $regex)   X-Ref
Utility function to map an object or array to an array

param: mixed    $item     The source object or array
param: boolean  $recurse  True to recurse through multi-level objects
param: string   $regex    An optional regular expression to match on field names
return: array

addColumn(array $array, array $column, $colName, $keyCol = null)   X-Ref
Adds a column to an array of arrays or objects

param: array   $array    The source array
param: array   $column   The array to be used as new column
param: string  $colName  The index of the new column or name of the new object property
param: string  $keyCol   The index of the column or name of object property to be used for mapping with the new column
return: array  An array with the new column added to the source array

dropColumn(array $array, $colName)   X-Ref
Remove a column from an array of arrays or objects

param: array   $array    The source array
param: string  $colName  The index of the column or name of object property to be removed
return: array  Column of values from the source array

getColumn(array $array, $valueCol, $keyCol = null)   X-Ref
Extracts a column from an array of arrays or objects

param: array   $array     The source array
param: string  $valueCol  The index of the column or name of object property to be used as value
param: string  $keyCol    The index of the column or name of object property to be used as key
return: array  Column of values from the source array

getValue($array, $name, $default = null, $type = '')   X-Ref
Utility function to return a value from a named array or a specified default

param: array|\ArrayAccess  $array    A named array or object that implements ArrayAccess
param: string              $name     The key to search for (this can be an array index or a dot separated key sequence as in Registry)
param: mixed               $default  The default value to give if no key found
param: string              $type     Return type for the variable (INT, FLOAT, STRING, WORD, BOOLEAN, ARRAY)
return: mixed

invert(array $array)   X-Ref
Takes an associative array of arrays and inverts the array keys to values using the array values as keys.

Example:
$input = array(
'New' => array('1000', '1500', '1750'),
'Used' => array('3000', '4000', '5000', '6000')
);
$output = ArrayHelper::invert($input);

Output would be equal to:
$output = array(
'1000' => 'New',
'1500' => 'New',
'1750' => 'New',
'3000' => 'Used',
'4000' => 'Used',
'5000' => 'Used',
'6000' => 'Used'
);

param: array  $array  The source array.
return: array

isAssociative($array)   X-Ref
Method to determine if an array is an associative array.

param: array  $array  An array to test.
return: boolean

pivot(array $source, $key = null)   X-Ref
Pivots an array to create a reverse lookup of an array of scalars, arrays or objects.

param: array   $source  The source array.
param: string  $key     Where the elements of the source array are objects or arrays, the key to pivot on.
return: array  An array of arrays pivoted either on the value of the keys, or an individual key of an object or array.

sortObjects(array $a, $k, $direction = 1, $caseSensitive = true, $locale = false)   X-Ref
Utility function to sort an array of objects on a given field

param: array  $a              An array of objects
param: mixed  $k              The key (string) or an array of keys to sort on
param: mixed  $direction      Direction (integer) or an array of direction to sort in [1 = Ascending] [-1 = Descending]
param: mixed  $caseSensitive  Boolean or array of booleans to let sort occur case sensitive or insensitive
param: mixed  $locale         Boolean or array of booleans to let sort occur using the locale language or not
return: array

arrayUnique(array $array)   X-Ref
Multidimensional array safe unique test

param: array  $array  The array to make unique.
return: array

arraySearch($needle, array $haystack, $caseSensitive = true)   X-Ref
An improved array_search that allows for partial matching of strings values in associative arrays.

param: string   $needle         The text to search for within the array.
param: array    $haystack       Associative array to search in to find $needle.
param: boolean  $caseSensitive  True to search case sensitive, false otherwise.
return: mixed    Returns the matching array $key if found, otherwise false.

flatten($array, $separator = '.', $prefix = '')   X-Ref
Method to recursively convert data to a one dimension array.

param: array|object  $array      The array or object to convert.
param: string        $separator  The key separator.
param: string        $prefix     Last level key prefix.
return: array

mergeRecursive(...$args)   X-Ref
Merge array recursively.

param: array  ...$args  Array list to be merged.
return: array  Merged array.



Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer