Array Macros
These macros are for working with arrays:
- listtoarray(list): Converts a list, like "1,2,3,4" or "cat,dog,rabbit" to an array
- explode(symbol, string): Converts a string to an array, breaking it apart on the given symbol.
- arraytolist(array): Converts an array to a list
- calclisttoarray(list): Converts a list of calculations, like "2^2,3^5,7/2" to an array, evaluating the calculations
along the way.
- stringtoarray(string): Converts a text string to an array of characters
- fillarray(value,num,[start]): Creates an array with num entries, all of which are the same given value. Array indexing
starts at 0 unless specified
- sortarray(list/array,[type, maxkey]): Sorts an array from lowest to highest value.
To sort in reverse order, give the option second parameter as "rev".
To sort by key, give the optional second parameter as "key".
To sort by key (numeric only) and fill in any missing numeric keys with empty string values,
give the optional second parameter as "keyfill". In this case you can optionally provide a third
argument for the max key to fill the array with.
- jointsort(array,array,[array,...]): Jointly reorders two or more arrays based on a lowest-to-highest sort of values in the first array
- consecutive(min,max,[step]): Creates an array of consecutive numbers, starting at min and ending at max, in increments of
step. Step is optional; it defaults to 1.
- calconarray(array,calculation): Returns an array, performing the given calculation on each element of the given array. Use
"x" as the variable to represent each element of the array. Example: $b = calconarray($a,"x^2") will create an array that is the
square each element of the array $a.
- multicalconarray(calculation,varslist,var1array,var2array,etc.) Returns an array, performing the given calculation on each set
of elements from the given arrays. Allows multivariable calculations. Example: $z= multicalconarray("x*y^2","x,y",$xs,$ys)
- calconarrayif(array,calculation,ifcondition): Like calconarray, but allows you to specify a condition for each element for whether to
do the calculation. Example: $b = calconarrayif($a,"x+.1","floor(x)==x") will add .1 to add whole numbers in the array, and leave the
other elements unchanged.
- keepif(array,condition) Filters an array, only keeping values that meet the
supplied condition. Example: keepif($a,"x%3==0").
- subarray(array,params): Creates a new array as a subset of the specified array. The params can take several forms:
- subarray($a,2,4,6): creates an array from $a[2], $a[4], and $a[6]
- subarray($a,"1:3","6:8"): create an array from $a[1] through $a[3], and $a[6] through $a[8]
- subarray($a,$b): creates an array from entries in $a with indexes specified in $b. So if $b = array(2,4,6), this
would return $a[2], $a[4], and $a[6]
- splicearray(array,offset,length,[replacement]): Removes the elements designated by offset and length from the given array, and replaces them with the elements of the replacement array, if supplied.
- joinarray(array,symbol): Convert an array to a string, joining elements with the given symbol
- mergearrays(array,array,[array,...]): Combines two or more arrays into one long array
- unionarrays(array,array): Unions two arrays, preventing duplicates, into a new array
- intersectarrays(array,array): Finds the intersection of two arrays
- diffarrays(array1,array2): Returns all elements in array1 that are not also in array2
- array_unique(array): Returns the array, stripping duplicate values. Beware this doesn't re-index the array, so you may want to then use array_values if you need consecutive array keys.
- array_values(array): Returns the values of an array, reindexing with consecutive numeric indices.
- array_keys(array): Returns the keys of an associative array.
- count(array): Counts the number of entries in the array
- is_array(variable): Determines if the variable is an array
- sumarray(array): Adds the entries in an array
- in_array(needle,haystack): Checks if value needle is in array haystack. Returns true or false
- arrayfindindex(needle,haystack): Returns the index in the array haystack of the value needle. If there are multiple matches, it only returns the first.
- arrayfindindices(needle,haystack): Returns an array of indices in the array haystack of the value needle.
- array_flip(array): Reverses a one-to-one array, so indexes become values and values become indexes