PHP Class a, kirby

显示文件 Open project: bastianallgeier/kirby Class Usage Examples

Public Methods

Method 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 method

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
return boolean true: the array contains the string, false: it doesn't

extract() static public method

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
return array The result array with all values from that column.

fill() static public method

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
return array The filled-up result array

first() static public method

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
return mixed The first element

get() static public method

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
return mixed

getall() static public method

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

inject() static public method

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
return array The result array including the new element

json() static public method

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
return string The JSON string

last() static public method

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
return mixed The last element

missing() static public method

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
return array An array of missing fields. If this is empty, nothing is missing.

remove() static public method

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.
return array The result array without the removed element

show() static public method

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.
return mixed If echo is false, this will return the generated array output.

shuffle() static public method

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

sort() static public method

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.
return array The sorted array

xml() static public method

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
return string The XML string