MDA (Multi Dimensional Array) access helpers for PHP
$array = array('test'=>array('test2'=>array('test3'=>'value')));
//get a key
$val = mda_get($array,'test.test2.test3'); //returns 'value'
//set a key
mda_set($array,'test.test2.test3','newvalue');
//add a key
mda_add($array,'test.test2.test4','value3');
//get the added key
$val = mda_get($array,'test.test2.test4.0'); //return 'value3'
MDA keys are used in every function. Sometimes they are referred to as "paths" or "path"
Returns the key from $arr
All of the set functions take the value as the last argument Example
mda_set($arr,'index1','index2','index3.index4','value');
Same as set except it adds the value as an anonymous index
mda_add($arr,'index1.index2','value');
//is the same as
$arr['index1']['index2'][] = 'value';
Delete a path from array
This will delete all values from a path
$arr['index'][0] = 'value';
$arr['index'][1] = 'value';
mda_del_value($arr,'index','value');
$count = count($arr['index']); //returns 0
This will check if a value exists in a path, same as mda_del_value()
Checks if a path exists
NOTE: this does not take a path it takes a keyname
Same prototype as PHPs implode with the enhanced functionality that it will take $join as an array If $join is a string it will pass directly to PHPs implode which is faster Example
$array = array(1,2,3,4,5);
$join = array('/','.',',');
$str = implodei($join,$array); //returns 1/2.3,4,5
NOTE: the last member of the array gets repeated
NOTE: THIS WILL NOT INCREASE THE ARRAYS POINTER (DOES NOT FUNCTION LIKE ARRAY_SHIFT) Use this to shift anonymous arrays only it does not reference the original array Otherwise its the same as PHPs array_shift()
Will recursively merge arrays similar to array_merge DOES NOT function like array_merge_recursive which is wrong
Language | php |
Version | 0.0.0 |
Git URL | https://github.com/nullivex/func-mda |
License | GPL-3.0 |
Description | MDA (Multi Dimensional Array) access helpers for PHP |
Keywords |