PHP Class a, kirby

Afficher le fichier Open project: bastianallgeier/kirby Class Usage Examples

Méthodes publiques

Méthode Description
contains ( array $array, string $search ) : boolean Checks if an array contains a certain string
extract ( array $array, string $key ) : array Extracts a single column from an array
fill ( array $array, integer $limit, mixed $fill = 'placeholder' ) : array Fills an array up with additional elements to certain amount.
first ( array $array ) : mixed Returns the first element of an array
get ( array $array, mixed $key, mixed $default = null ) : mixed Gets an element of an array by key
getall ( array $array, $keys ) : array Gets all elements for an array of key
inject ( array $array, integer $position, mixed $element = 'placeholder' ) : array Injects an element into an array
json ( array $array ) : string Converts an array to a JSON string It's basically a shortcut for json_encode()
last ( array $array ) : mixed Returns the last element of an array
missing ( array $array, array $required = [] ) : array Checks for missing elements in an array
remove ( array $array, mixed $search, boolean $key = true ) : array Removes an element from an array
search ( array $array, string $search ) : array Search for elements in an array by regular expression
show ( array $array, boolean $echo = true ) : mixed Shows an entire array or object in a human readable way This is perfect for debugging
shuffle ( array $array ) : array Shuffles an array and keeps the keys
sort ( array $array, string $field, string $direction = 'desc', const $method = SORT_REGULAR ) : array Sorts a multi-dimensional array by a certain column
xml ( array $array, string $tag = 'root', boolean $head = true, string $charset = 'utf-8', $tab = ' ', integer $level ) : string Converts an array to a XML string

Method Details

contains() static public méthode

Checks if an array contains a certain string
static public contains ( array $array, string $search ) : boolean
$array array The source array
$search string The string to search for
Résultat boolean true: the array contains the string, false: it doesn't

extract() static public méthode

Extracts a single column from an array
static public extract ( array $array, string $key ) : array
$array array The source array
$key string The key name of the column to extract
Résultat array The result array with all values from that column.

fill() static public méthode

Fills an array up with additional elements to certain amount.
static public fill ( array $array, integer $limit, mixed $fill = 'placeholder' ) : array
$array array The source array
$limit integer The number of elements the array should contain after filling it up.
$fill mixed The element, which should be used to fill the array
Résultat array The filled-up result array

first() static public méthode

I always have to lookup the names of that function so I decided to make this shortcut which is easier to remember.
static public first ( array $array ) : mixed
$array array The source array
Résultat mixed The first element

get() static public méthode

Gets an element of an array by key
static public get ( array $array, mixed $key, mixed $default = null ) : mixed
$array array The source array
$key mixed The key to look for
$default mixed Optional default value, which should be returned if no element has been found
Résultat mixed

getall() static public méthode

Gets all elements for an array of key
static public getall ( array $array, $keys ) : array
$array array The source array
Résultat array An array of keys and matching values

inject() static public méthode

Injects an element into an array
static public inject ( array $array, integer $position, mixed $element = 'placeholder' ) : array
$array array The source array
$position integer The position, where to inject the element
$element mixed The element, which should be injected
Résultat array The result array including the new element

json() static public méthode

Converts an array to a JSON string It's basically a shortcut for json_encode()
static public json ( array $array ) : string
$array array The source array
Résultat string The JSON string

last() static public méthode

I always have to lookup the names of that function so I decided to make this shortcut which is easier to remember.
static public last ( array $array ) : mixed
$array array The source array
Résultat mixed The last element

missing() static public méthode

This is very handy to check for missing user values in a request for example.
static public missing ( array $array, array $required = [] ) : array
$array array The source array
$required array An array of required keys
Résultat array An array of missing fields. If this is empty, nothing is missing.

remove() static public méthode

Removes an element from an array
static public remove ( array $array, mixed $search, boolean $key = true ) : array
$array array The source array
$search mixed The value or key to look for
$key boolean Pass true to search for an key, pass false to search for an value.
Résultat array The result array without the removed element

show() static public méthode

Shows an entire array or object in a human readable way This is perfect for debugging
static public show ( array $array, boolean $echo = true ) : mixed
$array array The source array
$echo boolean By default the result will be echoed instantly. You can switch that off here.
Résultat mixed If echo is false, this will return the generated array output.

shuffle() static public méthode

Shuffles an array and keeps the keys
static public shuffle ( array $array ) : array
$array array The source array
Résultat array The shuffled result array

sort() static public méthode

Sorts a multi-dimensional array by a certain column
static public sort ( array $array, string $field, string $direction = 'desc', const $method = SORT_REGULAR ) : array
$array array The source array
$field string The name of the column
$direction string desc (descending) or asc (ascending)
$method const A PHP sort method flag.
Résultat array The sorted array

xml() static public méthode

Converts an array to a XML string
static public xml ( array $array, string $tag = 'root', boolean $head = true, string $charset = 'utf-8', $tab = ' ', integer $level ) : string
$array array The source array
$tag string The name of the root element
$head boolean Include the xml declaration head or not
$charset string The charset, which should be used for the header
$level integer The indendation level
Résultat string The XML string