LFT
  • Namespace
  • Class
  • Tree

Namespaces

  • Docoflow
    • Contracts
    • Entity
    • Facades
    • Models
    • Traits
  • Docolight
    • Agno
      • Traits
    • Container
    • Http
      • Contracts
    • Rest
      • Handler
      • Http
    • Support
      • Debug
      • Traits
  • Docotory
    • Traits
  • None

Classes

  • ActiveRecordWrapper
  • Arr
  • Carbonate
  • ClassLoader
  • Collection
  • CollectionDataProvider
  • Facade
  • Factory
  • Fluent
  • Html
  • IterablePager
  • Repository
  • Set
  • Str

Class Arr

Array helper.

Docolight\Support\Arr uses Docolight\Support\Traits\Macroable
Namespace: Docolight\Support
Author: Krisan Alfa Timur krisanalfa@docotel.co.id
Located at Docolight/Support/Arr.php

Methods summary

public static array
# add( array $array, string $key, mixed $value )

Add an element to an array using "dot" notation if it doesn't exist.

Add an element to an array using "dot" notation if it doesn't exist.

Parameters

$array
$key
$value

Returns

array
public static array
# build( array $array, callable $callback )

Build a new array using a callback.

Build a new array using a callback.

Parameters

$array
$callback

Returns

array
public static array
# collapse( array|ArrayAccess $array )

Collapse an array of arrays into a single array.

Collapse an array of arrays into a single array.

Parameters

$array

Returns

array
public static array
# divide( array $array )

Divide an array into two arrays. One with keys and the other with values.

Divide an array into two arrays. One with keys and the other with values.

Parameters

$array

Returns

array
public static array
# dot( array $array, string $prepend = '' )

Flatten a multi-dimensional associative array with dots.

Flatten a multi-dimensional associative array with dots.

Parameters

$array
$prepend

Returns

array
public static array
# except( array $array, array|string $keys )

Get all of the given array except for a specified array of items.

Get all of the given array except for a specified array of items.

Parameters

$array
$keys

Returns

array
public static mixed
# first( array $array, callable $callback = null, mixed $default = null )

Return the first element in an array passing a given truth test.

Return the first element in an array passing a given truth test.

Parameters

$array
$callback
$default

Returns

mixed
public static mixed
# last( array $array, callable $callback = null, mixed $default = null )

Return the last element in an array passing a given truth test.

Return the last element in an array passing a given truth test.

Parameters

$array
$callback
$default

Returns

mixed
public static array
# flatten( array $array )

Flatten a multi-dimensional array into a single level.

Flatten a multi-dimensional array into a single level.

Parameters

$array

Returns

array
public static
# forget( array & $array, array|string $keys )

Remove one or many array items from a given array using "dot" notation.

Remove one or many array items from a given array using "dot" notation.

Parameters

$array
$keys
public static mixed
# get( array $array, string $key, mixed $default = null )

Get an item from an array using "dot" notation.

Get an item from an array using "dot" notation.

Parameters

$array
$key
$default

Returns

mixed
public static boolean
# has( array $array, string $key )

Check if an item exists in an array using "dot" notation.

Check if an item exists in an array using "dot" notation.

Parameters

$array
$key

Returns

boolean
public static array
# only( array $array, array|string $keys )

Get a subset of the items from the given array.

Get a subset of the items from the given array.

Parameters

$array
$keys

Returns

array
public static array
# pluck( array $array, string|array $value, string|array|null $key = null )

Pluck an array of values from an array.

Pluck an array of values from an array.

Parameters

$array
$value
$key

Returns

array
protected static array
# explodePluckParameters( string|array $value, string|array|null $key )

Explode the "value" and "key" arguments passed to "pluck".

Explode the "value" and "key" arguments passed to "pluck".

Parameters

$value
$key

Returns

array
public static mixed
# pull( array & $array, string $key, mixed $default = null )

Get a value from the array, and remove it.

Get a value from the array, and remove it.

Parameters

$array
$key
$default

Returns

mixed
public static array
# set( array & $array, string $key, mixed $value )

Set an array item to a given value using "dot" notation.

Set an array item to a given value using "dot" notation.

If no key is given to the method, the entire array will be replaced.

Parameters

$array
$key
$value

Returns

array
public static array
# sort( array $array, callable $callback )

Sort the array using the given callback.

Sort the array using the given callback.

Parameters

$array
$callback

Returns

array
public static array
# where( array $array, callable $callback )

Filter the array using the given callback.

Filter the array using the given callback.

Parameters

$array
$callback

Returns

array
public static array
# arToArray( CActiveRecord $model, boolean $withRelation = true, boolean $store = true )

Convert CActiveRecord implemetation to array, including all of it's relation.

Convert CActiveRecord implemetation to array, including all of it's relation.

Parameters

$model
Your model implementation.
$withRelation
Choose whether to fetch with your relation too or not.
$store
Store relation name in a temporary container. Useful to prefent infinite loop.

Returns

array

Link

CActiveRecord is the base class for classes representing relational data.
public static array
# group( array $array )

Flip your array, mostly comes from stackable form like this:.

Flip your array, mostly comes from stackable form like this:.

<input name="first-name[]" />
<input name="last-name[]" />

// It will produce $_POST array like this:

[ "first-name" => ["Ganesha", "Krisan", "Farid"], "last-name"  => ["Muharso", "Timur", "Hidayat"] ]

// This method will convert the array into this form:

[
 [ "first-name" => "Ganesha", "last-name" => "Muharso" ],
 [ "first-name" => "Krisan", "last-name" => "Timur" ],
 [ "first-name" => "Farid", "last-name" => "Hidayat" ]
]

// So you can loop them, and save them to your model via:

foreach(Arr::group($personInput) as $person) { $model = new User;
 $model->set($person)->save();
}

Parameters

$array

Returns

array
public static array
# groupBy( array $array, Closure $callback )

Group array based on return from closure.

Group array based on return from closure.

Parameters

$array
$callback

Returns

array
public static array
# pregOnly( string $pattern, array $input, integer $flags = 0 )

Get get array identified by a regex for it's index name.

Get get array identified by a regex for it's index name.

Parameters

$pattern
$input
$flags

Returns

array
public static array
# replaceKey( array $input, string|callable $search, string $replacement = '' )

Replace your array keys.

Replace your array keys.

$array = [ ':type_address'     => 'Foo', ':type_citizenship' => 'Bar', ':type_city'        => 'Baz', ':type_country'     => 'Qux' ]

Arr::replaceKey($array, ':type', 'user')

// Will produce

$array = [ 'user_address'     => 'Foo', 'user_citizenship' => 'Bar', 'user_city'        => 'Baz', 'user_country'     => 'Qux' ]

Parameters

$input
$search
$replacement

Returns

array
public static array
# replaceValue( array $input, string|callable $search, string $replacement = '' )

Replace your array value.

Replace your array value.

$header = [ ':type_address', ':type_citizenship', ':type_city', ':type_country' ]

Arr::replaceValue($header, ':type_')

// Will produce:

$header = [ 'address', 'citizenship', 'city', 'country' ]

Parameters

$input
$search
$replacement

Returns

array
public static integer
# depth( array $array )

Determine your multidimension array depth.

Determine your multidimension array depth.

Parameters

$array

Returns

integer
public static boolean
# isEmpty( array $array )

Determine if array is empty, works on multidimension array.

Determine if array is empty, works on multidimension array.

Parameters

$array
Array you want to check whether it's empty or not

Returns

boolean

Methods used from Docolight\Support\Traits\Macroable

__call(), __callStatic(), hasMacro(), macro()

Properties summary

protected static array $fetchedRelated
# array()

Properties used from Docolight\Support\Traits\Macroable

$macros

LFT API documentation generated by ApiGen