ArrayHelper

Type
Class
Namespace
Craft
Inherits
Craft\ArrayHelper
Since
1.0

Class ArrayHelper

See also http://craftcms.com

View source (opens new window)

# Public Methods

Method Description
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 (opens new window)

Arguments

Returns

array (opens new window)

Signature

public static array expandArray ( $arr )

# expandSettingsArray()

Signature

public static array expandSettingsArray ( $settings )

# filterEmptyStringsFromArray()

Filters empty strings from an array.

View source (opens new window)

Arguments

Returns

array (opens new window)

Signature

public static array filterEmptyStringsFromArray ( $arr )

# flattenArray()

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

View source (opens new window)

Arguments

Returns

array (opens new window)

Signature

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

# getFirstKey()

Returns the first key in a given array.

View source (opens new window)

Arguments

Returns

string (opens new window), integer (opens new window), null (opens new window) – 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 (opens new window)

Arguments

Returns

mixed, null (opens new window)

Signature

public static mixed, null getFirstValue ( $arr )

# prependOrAppend()

Prepends or appends a value to an array.

View source (opens new window)

Arguments

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 (opens new window)

Arguments

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

Returns

array (opens new window) – The trimmed array

Signature

public static array stringToArray ( $str )