You have to create an instance of Dot-Array includes your array, and you can create an empty instance by removing $array.
1// WAY 12$dot = dot($array);3 4// WAY 25$dot = new \Pharaonic\DotArray\DotArray($array);
This is list of the available methods that you can use with Dot-Array instance.
Sets a given key / value pair.
1$dot->set('users.*.created_at', date('r', time()));2 3// ArrayAccess4$dot['users.*.created_at'] = date('r', time());
Returns the value of a given key as an array.
1print_r($dot->get('users.*.name'));2 3// ArrayAccess4print_r($dot['users.*.name']);
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 key2echo $dot->toJson($key);3 4// All items5echo $dot->toJson();
Deletes the given key.
1$dot->delete('users.*.name');2 3// ArrayAccess4unset($dot['users.*.name']);
Checks if a given key exists (Boolean).
1$dot->has('users.7.name');2 3// ArrayAccess4isset($dot['users.7.name']);
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 key5$dot->count($key);6 7// OR use count() function [Countable Way]8count($dot);
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// ArrayAccess4empty($dot[$key]);5 6$dot->isEmpty();
Replaces all items in Dot object with a given array as a reference.
1$dot->setReference($array);