PHP Dot Notation Array Access: Access array elements using path strings with dots

Recommend this page to a friend!
  Info   View files Documentation   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-10-23 (8 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 64 This week: 1All time: 9,700 This week: 280Up
Version License PHP version Categories
php-dot-array 1.0.0Custom (specified...7PHP 5, Data types
Description Author

This package can be used to access array elements using path strings with dots.

It can perform several types of operations using strings to refer to indexes of elements in arrays that can have one or more dimensions.

The class provides functions that can perform operations like setting, getting, deleting array element values, check if an element exists with a given path, return array element count, etc..

Name: Moamen Eltouny <contact>
Classes: 10 packages by
Country: Egypt Egypt
Age: 27
All time rank: 366142 in Egypt Egypt
Week rank: 26 Up1 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 5x


[PHP] DotArray - Accessing arrays using dot notation and asterisk

Latest Stable Version Total Downloads License

DotArray provides an quick/easy access to arrays of data with dot-notation and asterisk.

//Get all users names with DotArray
$names = $dot->get('users.*.name');


Traditional way

$array['users']['raggi']['name'] = 'Moamen Eltouny';

echo $array['users']['raggi']['name']; // Moamen Eltouny

DotArray way (with DotArray Object)

$dot = dot(); // Creating DotArray Object
$dot->set('', 'Moamen Eltouny');

// Getting [DotArray way]
echo $dot->get('');

// OR Getting [ArrayAccess way]
echo $dot[''];


Install the latest version using Composer:

$ composer require raggitech/php-dot-array


Create a new DotArray object:

$dot = new \RaggiTech\DotArray\DotArray;

// With existing array
$dot = new \RaggiTech\DotArray\DotArray($array);

OR You can use a helper function to create the object:

$dot = dot();

// With existing array
$dot = dot($array);


DotArray has the following methods:

<a name="set"></a>


Sets a given key / value pair:

$dot->set('users.raggi.created_at', date('r', time()));

// ArrayAccess
$dot['users.raggi.created_at'] = date('r', time());

<a name="get"></a>


Returns the value of a given key:


// ArrayAccess

Returns a given default value, if the given key doesn't exist:

print_r($dot->get('users.*.name', 'Raggi'));

<a name="tojson"></a>


Returns the value of a given key (like get() method) as JSON:

echo $dot->toJson('users');

Returns all the stored items (like get() method) as JSON:

echo $dot->toJson();

<a name="all"></a>


Returns all the stored items as an array:

$values = $dot->all();

<a name="delete"></a>


Deletes the given key:


// ArrayAccess

<a name="clear"></a>


Deletes all the stored items:


<a name="has"></a>


Checks if a given key exists (returns boolean):


// ArrayAccess

<a name="count"></a>


Returns the number of the root Items:


// Or use count() function [Countable Way]

Returns the number of items in a given key:


<a name="isempty"></a>


Checks if a given key is empty (returns boolean):


// ArrayAccess

Checks the whole DotArray object:


<a name="setarray"></a>


Replaces all items in DotArray object with a given array:


<a name="setreference"></a>


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



MIT license

  Files folder image Files  
File Role Description
Files folder imagesrc (2 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file DotArray.php Class Class source
  Accessible without login Plain text file helper.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
This week:1
All time:9,700
This week:280Up

For more information send a message to info at phpclasses dot org.