ArrayHelper

Type
Class
Namespace
Craft
Inherits
Craft\ArrayHelper
Since
1.0

Class ArrayHelper

See also http://craftcms.com

View source

Public Methods

MethodDescription
expandArray()Expands a flattened array back into its original form
expandSettingsArray()
filterEmptyStringsFromArray()Filters empty strings from an array.
flattenArray()Flattens a multi-dimensional array into a single-dimensional array.
getFirstKey()Returns the first key in a given array.
getFirstValue()Returns the first value in a given array.
prependOrAppend()Prepends or appends a value to an array.
stringToArray()Converts a comma-delimited string into a trimmed array, ex:

expandArray()

Expands a flattened array back into its original form

View source

Arguments

Returns

array

Signature

public static array expandArray ( $arr )

expandSettingsArray()

View source

Arguments

  • $settings

Returns

array

Signature

public static array expandSettingsArray ( $settings )

filterEmptyStringsFromArray()

Filters empty strings from an array.

View source

Arguments

Returns

array

Signature

public static array filterEmptyStringsFromArray ( $arr )

flattenArray()

Flattens a multi-dimensional array into a single-dimensional array.

View source

Arguments

Returns

array

Signature

public static array flattenArray ( $arr, $prefix = null )

getFirstKey()

Returns the first key in a given array.

View source

Arguments

Returns

string, integer, null – The first key, whether that is a number (if the array is numerically indexed) or a string, or null if $arr isn’t an array, or is empty.

Signature

public static string, integer, null getFirstKey ( $arr )

getFirstValue()

Returns the first value in a given array.

View source

Arguments

Returns

mixed, null

Signature

public static mixed, null getFirstValue ( $arr )

prependOrAppend()

Prepends or appends a value to an array.

View source

Arguments

  • $arr
  • $value (mixed)
  • $prepend (boolean)

Signature

public static void prependOrAppend ( &$arr, $value, $prepend )

stringToArray()

Converts a comma-delimited string into a trimmed array, ex: ArrayHelper::stringToArray('one, two, three') => array('one', 'two', 'three')

View source

Arguments

  • $str (mixed) – The string to convert to an array

Returns

array – The trimmed array

Signature

public static array stringToArray ( $str )