PHP Класс a, kirby

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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

Описание методов

contains() статический публичный Метод

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
Результат boolean true: the array contains the string, false: it doesn't

extract() статический публичный Метод

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
Результат array The result array with all values from that column.

fill() статический публичный Метод

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
Результат array The filled-up result array

first() статический публичный Метод

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
Результат mixed The first element

get() статический публичный Метод

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
Результат mixed

getall() статический публичный Метод

Gets all elements for an array of key
static public getall ( array $array, $keys ) : array
$array array The source array
Результат array An array of keys and matching values

inject() статический публичный Метод

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
Результат array The result array including the new element

json() статический публичный Метод

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
Результат string The JSON string

last() статический публичный Метод

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
Результат mixed The last element

missing() статический публичный Метод

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
Результат array An array of missing fields. If this is empty, nothing is missing.

remove() статический публичный Метод

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.
Результат array The result array without the removed element

show() статический публичный Метод

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.
Результат mixed If echo is false, this will return the generated array output.

shuffle() статический публичный Метод

Shuffles an array and keeps the keys
static public shuffle ( array $array ) : array
$array array The source array
Результат array The shuffled result array

sort() статический публичный Метод

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.
Результат array The sorted array

xml() статический публичный Метод

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
Результат string The XML string