Extension:ArrayFunctions

The ArrayFunctions extension creates an additional set of pure, Parsoid-compatible parser functions that operate on arrays.

The extension works by using pure parser functions. Instead of manipulating some previously defined array, a pure parser function takes some arguments, performs some calculation, and returns the result. Arrays, and other data types, are passed around as opaque data types.

af_bool
This parser function casts a string to a boolean. This is useful for creating an array containing a boolean.

Parameters

 * value : string or boolean
 * The value to cast to a boolean.

Return values
Returns the casted boolean.

af_count
This parser functions counts the number of values in an array.

Parameters

 * array : array
 * The array to count.


 * recursive : boolean, default=false
 * Whether to count items recursively. Note that elements containing a list are also counted (see examples below).

Return values
The number of items in the array.

af_exists
This parser function checks whether the given key or index in an array exists.

Parameters

 * array : array
 * The array to check.


 * key : string or int
 * The key to check.

Return values
Returns true if  contains , false otherwise.

af_float
This parser function casts a string to a float. This is useful for creating an array containing a float.

Parameters

 * value : string or float
 * The value to cast to a float.

Return values
Returns the casted float.

af_foreach
This parser function provides a way to iterate over arrays.

Parameters

 * array : array
 * The array over which to iterate.


 * keyName : string, default=null
 * The name to use for the key.


 * valueName : string, default=null
 * The name to use for the value.


 * body : string
 * The body to return for each iteration.

Return values
Returns the resulting wikitext.

af_get
This parser function is used to index in an array.

Parameters

 * array : array
 * The array in which to index.


 * * indices : string
 * The index. Multiple indices can be given to index nested arrays.

Return values
Returns the indexed value, or the empty string if the index does not exist.

af_int
This parser function casts a string to an integer. This is useful for creating an array containing an integer.

Parameters

 * value : string or int
 * The value to cast to an integer.

Return values
Returns the casted integer.

af_isarray
This parser function checks if the given value is an array.

Parameters

 * value : mixed
 * The value to check.

Return values
Returns true if  is an array, false otherwise.

af_join
This parser function recursively joins the items of an array together with a given separator.

Parameters

 * glue : string, default=""
 * The string used to join each item. This parameter recognises the following escape sequences:
 * for spaces
 * for newlines
 * for backslashes


 * array : array
 * The array to join.

Return values
Returns the joined array.

af_keysort
This parser function sorts a multidimensional array based on the values of a key.

Parameters

 * array : array
 * The array to sort.


 * key : string
 * The key of the values on which the sort should be based.


 * descending : boolean, default=false
 * Whether to sort in a descending order.

Return values
Returns the sorted array.

af_list
This parser function creates a new list from the given parameters.

Parameters

 * * values : mixed
 * The values for the list.

Return values
Returns the resulting list.

af_map
This parser function applies a callback to each element of a list.

Parameters

 * array : array
 * The array to run through the callback.


 * valueName : string
 * The name to give to the value in the callback.


 * callback : string
 * The callback to apply to each element of the array.

Return values
Returns the resulting mapped array.

af_object
This parser function creates a new object from the given parameters.

Parameters

 * ** values : mixed
 * The values for the object.

Return values
Returns the resulting object.

af_print
This parser function prints the given value in a human-readable format.

Parameters

 * value : mixed
 * The value to print.

Return values
Returns the value in human-readable form.

af_push
This parser function adds the given value to the end of the list.

Parameters

 * array : array
 * The array to append the value to.


 * value : mixed
 * The value to add.

Return values
Returns the array with the value appended.

af_sort
This parser function sorts the given list.

Parameters

 * array : array
 * The array to sort.


 * descending : boolean, default=false
 * Whether to sort the list in descending order.

Return values
Returns the sorted list.

af_unique
This parser function removes duplicate values from the given array.

Parameters

 * array : array
 * The array from which to remove duplicates.

Return values
Returns the array with duplicates removed.