Returns the count of elements contained in an array:
{array_count( array( 1, 2, 3, 4 ) )}
returns the value 4.
Returns true if the value $v exists in the array $a:
{array_contains( array( 1, 2, 3 ), 2 )}
will evaluate to true, while:
{array_contains( array( 1, 2, 3 ), 4 )}
gives false.
Returns true if an array contains an element.
{array_is_empty( array( 1, 2, 3 ) )}
will evaluate to false, while:
{array_is_empty( array() )}
gives true.
Returns the index of a specific element value ($v) in the array or boolean false, when the
element is not contained in the array:
{array_index_of( array( "a" => "b", "c" => "d" ), "b" )}
will return "a", while:
{array_index_of( array( "a" => "b", "c" => "d" ), "c" )}
will return false, since "c" is not an element contained in the array.
Returns whether an $index exists in an array:
{array_index_exists( array( 1, 2, 3 ), 1 )}
will return true, while:
{array_index_exists( array( 1, 2, 3 ), 10 )}
returns false.
Returns the left part of an array with the specified length ($len):
{array_left( array( 1, 2, 3, 4 ), 2 )}
returns the following array:
array( 1, 2 )
Returns the right part of an array with the specified length ($len):
{array_right( array( 1, 2, 3, 4 ), 2 )}
returns the following array:
array( 3, 4 )
Returns a part from the middle of an array, that starts at a specific $index
with the specified length ($len):
{array_mid( array( 1, 2, 3, 4 ), 1, 2 )}
returns the following array:
array( 2, 3 )
Returns an array, where the additional elements $v1, $v2, ... have been
inserted into the source array ($a) have been inserted starting from
$index:
{array_insert( array( 1, 2, 3 ), 1, "a", "b" )}
returns the following array:
array( 1, "a", "b", 2, 3 )
Returns an array with the additional values $v1, $v2, ... appended to the
original array ($a):
{array_append( array( 1, 2, 3 ), 4, 5 )}
returns the following array:
array( 1, 2, 3, 4, 5 )
Returns an array with the additional values $v1, $v2, ... prepended to the
original array ($a):
{array_append( array( 1, 2, 3 ), 4, 5 )}
returns the following array:
array( 4, 5, 1, 2, 3 )
Returns 2 or more arrays merged into 1 single array:
{array_merge( array( "a" => "a", "b" => "b", "c" => "c" ), array( "a" => 1, "c" => 2) )}
returns the following array:
array( "a" => 1, "b" => "b", "c" => 2 )
Returns an array which results from the given array, where the portion starting
at $index, with the length $len has been removed:
{array_remove( array( 1, 2, 3, 4, 5 ), 1, 2 )}
returns the following array:
array( 1, 4, 5 )
Returns an array with the first part with the specified length $len of the
original array ($a) removed. If $len is omitted, 1 is assumed and the first
element is removed:
{array_remove_first( array( 1, 2, 3, 4 ), 2 )}
returns the following array:
array( 3, 4 )
Returns an array with the last part with the specified length $len of the
original array ($a) removed. If $len is omitted, 1 is assumed and the first
element is removed:
{array_remove_first( array( 1, 2, 3, 4 ), 2 )}
returns the following array:
array( 1, 2 )
Returns an array, where a given part in the original array has been
replaced. The part to replace starts with $index and is $len elements
long. The defined portion is replaced with the given values $v1, $v2,...
{array_replace( array( 1, 2, 3, 4 ), 1, 2, "a", "b", "c" )}
returns the following array:
array( 1, "a", "b", "c", 4 )
Returns an array where the 2 indices $index1 and $index2 are swapped:
{array_swap( array( 1, 2, 3, 4 ), 1, 3 )}
returns the following array:
array( 1, 4, 3, 2 )
Returns an array where the elements are in reverse order as for the original
array:
{array_reverse( array( 1, 2, 3 ) )}
returns the following array:
array( 3, 2, 1 )
Returns an array containing all the values of $a1 that are not present in
any of the other arguments ($a2, $a3,...):
{array_diff( array( 1, 2, 3, 4 ), array( 2, 4 ), array( 5 ) )}
returns the following array:
array( 1, 3 )
Returns an array containing all the values of $a1 that are present in all
the other arguments ($a2, $a3,...):
{array_intersect( array( 1, 2, 3, 4 ), array( 2 ), array( 4 ) )}
returns the following array:
array( 2, 4 )
Fills an array $a with the given fill value $fill to a specific length. If
the submitted array already contains values, those will not be overwritten:
{array_pad( array( 1, 2, 3 ), 5, "a" )}
returns the following array:
array( 1, 2, 3, "a", "a" )
Returns the submitted array without any duplicate values:
{array_unique( array( 1, 2, 2, 3, 2, 4, 2, 2 ) )}
returns the following array:
array( 1, 2, 3, 4 )
Returns the key of the submitted value $v in the submitted array $a. If the
value is not found, this function returns boolean false:
{array_find( array( 1, 2, 3, 4 ), 3 )}
returns the key 2.
Returns an array where a specific value $v1 from the original array $a has
been replaced with the new value $vNew:
{array_find_replace( array( 1, 2, 3 ), 2, "a" )}
returns the following array:
array( 1, "a", 3 )
Returns an array of elements $from low to $high, inclusive. If $low >
$high, the sequence will be from $high to $low. If a $step value is given,
it will be used as the increment between elements in the sequence. $step should
be given as a positive number. If not specified, step will default to 1:
{array_fill_range( 0, 10, 2 )}
returns the following array:
array( 0, 2, 4, 6, 8, 10 )
Returns the sum of the elements in the given array:
{array_sum( array( 5, 5, 10, 20 ) )}
returns 40.
Returns an array of extracted properties from an array of objects. The
properties named in the $pList array. Each property becomes a new value in
the resulting array:
{use $productsArray}
{var $priceArray = array_extract_by_properties( $productsArray, array( "price" ) )}
{debug_dump( $priceArray )}
The first line of the code above imports an array with product objects. A
product object has at least one property price. Meaning that:
{$productArray[0]->price}
returns the price of the first product in the array. The function
array_extract_by_properties goes through the whole array of products and
stores the price in the array. The output can be something like:
array
(
[0] => 200
[1] => 199.24
[2] => 50.20
)
Returns an array containing all the values of $a1 that are not present in
any of the other arguments ($a2, $a3,...). With this function (in contrast
to array_diff) the keys are considered, too:
{hash_diff( array( "a" => "a", "b" => "b" ), array( "a" => "a", "c" => "b" ) )}
returns the following array:
array( "b" => "b" )
Returns an array containing all the values of $a1 that are not present in
any of the other arguments ($a2, $a3,...). This function (in contrast
to array_diff) the keys are used for comparison:
{hash_diff( array( "a" => "a", "b" => "b" ), array( "a" => "a", "c" => "b" ) )}
returns the following array:
array( "b" => "b" )
Returns an array containing all the values of $a1 that are present in all
the other arguments ($a2, $a3,...). In contrast to array_intersect this
function performs additional key checks:
{hash_intersect( array( "a" => "a", "b" => "b" ), array( "a" => "a", "b" => "c" ) )}
returns the following array:
array( "a" => "a" )
Returns an array containing all the values of $a1 that are present in all
the other arguments ($a2, $a3,...). In contrast to array_intersect this
function checks the keys instead of the values:
{hash_intersect_key( array( "a" => "a", "b" => "b" ), array( "a" => "a", "b" => "c" ) )}
returns the following array:
array( "a" => "a", "b" => "c" )
Returns the keys of the provided array as an array:
{hash_keys( array( "a" => 1, "b" => 2 ) )}
returns the following array:
array( "a", "b" )
Returns the values of the provided array as an array:
{hash_values( array( "a" => 1, "b" => 2 ) )}
returns the following array:
array( 1, 2 )
Returns an array, which has the values of the original array $a as the keys,
which are assigned to the keys of the original array:
{hash_flip( array( "a" => "apple", "b" => "banana", "c" => "banana" ) )}
returns the following array:
array( "apple" => "a", "banana" => "c" )
Returns a multidimensional array, which has $len elements, which all contain
the array $a:
{array_repeat( array( 1, 2 ), 2 )}
returns an array:
array( array( 1, 2 ), array( 1, 2 ) )
Returns a sorted version of the array:
{array_sort( array( 1, 3, 2, 5, 4 ) )}
returns the following array:
array( 1, 2, 3, 4, 5 )
Returns a sorted version of the array, but in reverse order:
{array_sort_reverse( array( 1, 3, 2, 5, 4 ) )}
returns the following array:
array( 5, 4, 3, 2, 1 )
Returns a sorted version of the array, but maintains the key => value
association:
{hash_sort( array( "a" => "banana", "b" => "apple" ) )}
returns the following array:
array( "b" => "apple", "a" => "banana" )
Returns a reverse sorted version of the array:
{hash_sort( array( "a" => "banana", "b" => "apple" ) )}
returns the following array:
array( "apple", "banana" )
Returns a sorted version of the array, sorted by the keys of the array:
{hash_sort( array( "a" => "banana", "b" => "apple" ) )}
returns the following array:
array( "a" => "banana", "b" => "apple" )
Returns a sorted version of the array, sorted by the keys of the array in
reverse order:
{hash_sort( array( "a" => "banana", "b" => "apple" ) )}
returns the following array:
array( "b" => "apple", "a" => "banana" )
Replaces the part between $index and $index + $length from the string
$before with $replace:
{str_replace( "Hello world!", 6, 5, "earth" )}
Outputs:
Hello earth!
See also: str_find_replace.
Removes the part between index and index + length from the string
before:
{str_remove( "Hello world!", 6, 5)}
Outputs:
Hello!
Removes the number amount of characters from the end of the string:
{str_chop( "Hello world!", 7)}
Outputs:
Hello
Removes the $number amount of characters from the beginning of the string:
{str_chop_front( "Hello world!", 6)}
Outputs:
world!
Appends the string $s2 to the string $s1:
{str_append( "Hello", " world!")}
Outputs:
Hello world!
Note that this function is the same as using the dot operator.
See also str_prepend ().
Prepends the string $s2 to the string $s1:
{str_prepend( "Hello", " world!")}
Outputs:
world!Hello
Note that this function is the same as using the dot operator with switched arguments.
See also str_append ().
Compares string $s1 with $s2 and returns 0 if both strings are equal. This function
returns a negative value if $s1 is smaller than $s2 and returns a positive value if
$s1 is greater than $s2:
{str_compare( "Bernard", "Bernard") // = 0 }
{str_compare( "Bernard", "Fran" ) // > 0 }
{str_compare( "Fran", "Bernard" ) // < 0 }
See also str_nat_compare ().
Compares string $s1 with $s2 with a 'natural order' algorithm. This function returns 0 if
both strings are equal. A negative value is returned if $s1 is smaller than $s2 and a positive
value is returned if $s1 is greater than $s2.
The difference between str_nat_compare() and str_compare () is how numbers are compared:
{ str_compare( "img1.png", "img10.png" ) // > 0 }
{ str_nat_compare( "img1.png", "img10.png" ) // < 0 }
The first function sorts pure alphabetically. The second functions recognizes the number
and therefore says that 'img10' comes after (has a higher number) than 'img1'.
See also str_compare ().
Returns true if the substring $find is found in the source string $source,
otherwise this function returns false:
{ str_contains( "Don't you dare use the word 'party' as a verb in this shop!", "party" ) }
Returns true.
See also str_index_of (), str_last_index ().
Returns the string length, the amount of characters of the string $str:
{ str_len( "Bernard" )}
Outputs:
7
Returns the 'left' $length characters of the string $str:
{str_left( "Bernard Black" , 7)}
Outputs:
Bernard
See also str_right (), str_mid ().
Returns true if the string $s1 starts with $s2:
{str_starts_with( "Bernard Black" , "Bernard")}
See also str_ends_with ().
Returns the 'right' $length characters of the string $str:
{str_right( "Bernard Black" , 5)}
Outputs:
Black
See also str_left (), str_mid ().
Returns true if the string $s1 ends with $s2:
{str_ends_with( "Bernard Black" , "Black")}
See also str_starts_with ().
Returns the sub-string between $index and $index + $length from the string $str:
{ str_mid( "Bernard Ludwig Black", 8, 6)
Outputs:
Ludwig
Returns the character that is at position $pos in the string $str:
{str_at( "Bernard", 2 )}
Outputs the character 'r'.
Repeats the string $str for $repeat times and returns it:
{str_fill( "-", 5 )}
Outputs:
-----
Searches the string $search in $source and returns the begin position of the first
occurrence. If an $offset is given, the searching starts at this position. This
function returns false if the $search string couldn't be found in the $source:
{str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "party" ) }
{str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "a" ) }
{str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "a", 12 ) }
Outputs:
29
11
30
See also str_contains (), str_last_index ().
Does a reverse search the string $search in $source and returns the begin position of the first
occurrence. If an $offset is given, the searching starts at this position. This
function returns false if the $search string couldn't be found in the $source:
{str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "party" ) }
{str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "a" ) }
{str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "a", 38 ) }
Outputs:
29
39
36
See also str_contains (), str_last_index ().
Returns true if the given string $str is empty, otherwise it returns false:
{str_is_empty( "" ) // true}
Pads the string $str to the length $length with the string $fill.
The padding will be prepended to the string $str:
{str_pad_left( " You got the BFG", 20, "-" )}
Outputs:
---- You got the BFG
Pads the string $str to the length $length with the string $fill.
The padding will be appended to the string $str:
{str_pad_right( "You got the BFG ", 20, "-" )}
Outputs:
You got the BFG ----
Formats the number $number with the given amount of decimals $decimals, separated with the
$decimal_sep character. Thousands are separated with the $thousands_sep character:
{number_format( 30000.141234, 2, ".", "," )}
Outputs:
3,000.14
Removes whitespace characters or other characters from the beginning and end of the string.
If no $charlist is given, the following characters will be removed:
| ' ': | Ordinary whitespaces. |
| \t: | A tab. |
| \n: | A newline. |
| \r: | A carriage return. |
| \0: | A null byte. |
If a $charlist is given, then the characters in that string will be stripped instead:
{ str_trim( " ...Whoohooo.. " )}
{ str_trim( " ...Whoohooo.. ", "." )}
{ str_trim( " ...Whoohooo.. ", " ." )}
Outputs:
...Whoohooo..
...Whoohooo..
Whoohooo
See also str_trim_left (), str_trim_right ().
Removes whitespace characters or other characters from the beginning of the string.
This function works the same as str_trim (), except that the characters on the right side are not trimmed:
{ str_trim_left( " ...Whoohooo.. " )}
{ str_trim_left( " ...Whoohooo.. ", "." )}
{ str_trim_left( " ...Whoohooo.. ", " ." )}
Outputs:
...Whoohooo..
...Whoohooo..
Whoohooo..
See also str_trim (), str_trim_right ().
Removes whitespace characters or other characters from the end of the string.
This function works the same as str_trim (), except that the characters on the left side are not trimmed:
{ str_trim_left( " ...Whoohooo.. " )}
{ str_trim_left( " ...Whoohooo.. ", "." )}
{ str_trim_left( " ...Whoohooo.. ", " ." )}
Outputs:
...Whoohooo
...Whoohooo..
...Whoohooo
See also str_trim (), str_trim_left ().
Substitutes newlines, tabs, and multiple spaces from the string $str and replaces it with a single blank.
Whitespace in the beginning and at the end of the $str are removed:
{ str_simplify( " my\t \n string \n ") }
Outputs:
my string
Splits the string $str with the $separator and returns it as an array. If a maximum max is given, the
return array will consist of maximum $max elements:
{str_split( "Bernard-Ludwig-Black", "-" )}
Will return an array with the elements:
[0] => "Bernard",
[1] => "Ludwig",
[2] => "Black".
See also str_join ().
Joins an array with strings, $array together. Between each element a separator is
inserted:
{join( array( "Bernard", "Ludwig", "Black" ) , "-" }
Outputs:
Bernard-Ludwig-Black
Returns one character string with the ASCII value $char:
{str_ord( 65 )}
Outputs:
A
Returns a string with only upper case characters of the source string $str:
{ str_upper( "hEllO worLD" ) }
Outputs:
HELLO WORLD
See also str_lower ().
Returns a string with only lower case characters of the source string $str:
{ str_lower( "hEllO worLD" ) }
Outputs:
hello world
See also str_upper ().
Returns a string of which the first character is capitalized. Other characters
remain unchanged:
{str_capitalize( "hello WORLD")}
Outputs:
Hello WORLD
Searches for the string find in the string source. The first occurence will
be replaced with the string replace. If the last parameter count is given,
the amount of replacements is limited to this number:
{str_find_replace( "Hello world!", "world", "earth")}
Outputs:
Hello earth!
Returns the reversed string of $str:
{str_reverse( "Hello world" )}
Outputs:
dlrow olleH
Returns the number of characters in the given string $str:
{str_char_count("Hello")}
Outputs:
5
This method is the same as str_len ().
See also str_word_count (), str_paragraph_count ().
Returns the number of words in the given string $str. If no
word separator $word_sep is given, the default word seperator
is a whitespace:
{str_word_count("Just a random sentence")}
Outputs:
4
See also str_char_count (), str_paragraph_count ().
Returns the number of paragraphs in the given string $str. Each
paragraph is supposed to be split a blank line:
{str_paragraph_count(
"The first paragraph
The second paragraph" )}
Outputs:
2
Returns a wrapped string of the source string $str. The $width specifies after how
the $break character should be inserted. If $cut_word is given and
set to true, it will directly insert the $break in the word. Otherwise the word will be
finished and the $break will be inserted after the word:
{str_wrap("Don't you dare use the word 'party' as a verb in this shop!", 20, "<br/>\n") }
{str_wrap("Don't you dare use the word 'party' as a verb in this shop!", 20, "\n", true) }
Outputs:
Don't you dare use the <br/>
word 'party' as a verb <br/>
in this shop!
Don't you dare use t
he word 'party' as a
verb in this shop!
Returns a MIME base64 encoded string from the $str:
{str_base64_encode( "I don't want to be encoded!" )}
Outputs:
SSBkb24ndCB3YW50IHRvIGJlIGVuY29kZWQh
Decodes the given MIME base64 $str and returns the original data:
{str_base64_decode( "SSBkb24ndCB3YW50IHRvIGJlIGVuY29kZWQh" )}
Outputs:
I don't want to be encoded!