Pharaonic
Loading...

# Create Dot-Array

You have to create an instance of Dot-Array includes your array, and you can create an empty instance by removing $array.

1// WAY 1
2$dot = dot($array);
3 
4// WAY 2
5$dot = new \Pharaonic\DotArray\DotArray($array);

# Available Methods

This is list of the available methods that you can use with Dot-Array instance.

# set

Sets a given key / value pair.

1$dot->set('users.*.created_at', date('r', time()));
2 
3// ArrayAccess
4$dot['users.*.created_at'] = date('r', time());

# get

Returns the value of a given key as an array.

1print_r($dot->get('users.*.name'));
2 
3// ArrayAccess
4print_r($dot['users.*.name']);

# all

Returns all the stored items as an array.

1$values = $dot->all();

# toJson

Returns the value of a given key as JSON
But if you want to get all the stored items as an JSON just remove $key.

1// Specific key
2echo $dot->toJson($key);
3 
4// All items
5echo $dot->toJson();

# delete

Deletes the given key.

1$dot->delete('users.*.name');
2 
3// ArrayAccess
4unset($dot['users.*.name']);

# clear

Deletes all the stored items.

1$dot->clear();

# has

Checks if a given key exists (Boolean).

1$dot->has('users.7.name');
2 
3// ArrayAccess
4isset($dot['users.7.name']);

# count

Returns the number of the root Items
but if you want to count depends on a specific key you can do it too.

1// All items
2$dot->count();
3 
4// Specific key
5$dot->count($key);
6 
7// OR use count() function [Countable Way]
8count($dot);

# isEmpty

Checks if a given key is empty (Boolean)
But if you want to check that there is any item or no .. so you have to remove $key.

1$dot->isEmpty($key);
2 
3// ArrayAccess
4empty($dot[$key]);
5 
6$dot->isEmpty();

# setArray

Replaces all items in DotArray object with a given array.

1$dot->setArray($array);

# setReference

Replaces all items in Dot object with a given array as a reference.

1$dot->setReference($array);