Array: set value using dot notation? - php

Looking into Kohana documentation, i found this really usefull function that they use to get values from a multidimensional array using a dot notation, for example:
$foo = array('bar' => array('color' => 'green', 'size' => 'M'));
$value = path($foo, 'bar.color', NULL , '.');
// $value now is 'green'
Im wondering if there is a way to set the an array value in the same way:
set_value($foo, 'bar.color', 'black');
The only way i found to do that is re-building the array notation ($array['bar']['color']) and then set the value.. using eval.
Any idea to avoid eval?

function set_val(array &$arr, $path,$val)
{
$loc = &$arr;
foreach(explode('.', $path) as $step)
{
$loc = &$loc[$step];
}
return $loc = $val;
}

Sure it's possible.
The code
function set_value(&$root, $compositeKey, $value) {
$keys = explode('.', $compositeKey);
while(count($keys) > 1) {
$key = array_shift($keys);
if(!isset($root[$key])) {
$root[$key] = array();
}
$root = &$root[$key];
}
$key = reset($keys);
$root[$key] = $value;
}
How to use it
$foo = array();
set_value($foo, 'bar.color', 'black');
print_r($foo);
Outputs
Array
(
[bar] => Array
(
[color] => black
)
)
See it in action.

Look at https://gist.github.com/elfet/4713488
$dn = new DotNotation(['bar'=>['baz'=>['foo'=>true]]]);
$value = $dn->get('bar.baz.foo'); // $value == true
$dn->set('bar.baz.foo', false); // ['foo'=>false]
$dn->add('bar.baz', ['boo'=>true]); // ['foo'=>false,'boo'=>true]

That way you can set the following values ​​more than once to the same variable.
You can make these two ways (by static variable and reference variable):
<?php
function static_dot_notation($string, $value)
{
static $return;
$token = strtok($string, '.');
$ref =& $return;
while($token !== false)
{
$ref =& $ref[$token];
$token = strtok('.');
}
$ref = $value;
return $return;
}
$test = static_dot_notation('A.1', 'A ONE');
$test = static_dot_notation('A.2', 'A TWO');
$test = static_dot_notation('B.C1', 'C ONE');
$test = static_dot_notation('B.C2', 'C TWO');
$test = static_dot_notation('B.C.D', 'D ONE');
var_export($test);
/**
array (
'A' =>
array (
1 => 'A ONE',
2 => 'A TWO',
),
'B' =>
array (
'C1' => 'C ONE',
'C2' => 'C TWO',
'C' =>
array (
'D' => 'D ONE',
),
),
*/
function reference_dot_notation($string, $value, &$array)
{
static $return;
$token = strtok($string, '.');
$ref =& $return;
while($token !== false)
{
$ref =& $ref[$token];
$token = strtok('.');
}
$ref = $value;
$array = $return;
}
reference_dot_notation('person.name', 'Wallace', $test2);
reference_dot_notation('person.lastname', 'Maxters', $test2);
var_export($test2);
/**
array (
'person' =>
array (
'name' => 'Wallace',
'lastname' => 'Maxters',
),
)
*/

I created a small class just for this!
http://github.com/projectmeta/Stingray
$stingray = new StingRay();
//To Get value
$stingray->get($array, 'this.that.someother'):
//To Set value
$stingray->get($array, 'this.that.someother', $newValue):

Updated #hair resins' answer to cater for:
When a sub-path already exists, or
When a sub-path is not an array
function set_val(array &$arr, $path,$val)
{
$loc = &$arr;
$path = explode('.', $path);
foreach($path as $step)
{
if ( ! isset($loc[$step]) OR ! is_array($loc[$step]))
$loc = &$loc[$step];
}
return $loc = $val;
}

None of the examples here worked for me, so I came up with a solution using eval() (read about the risks here, but if you don't use user data, it shouldn't be much of an issue). The if-clause in the set-method allows you to push your item onto a new or existing array at that location ($location[] = $item).
class ArrayDot {
public static function get(array &$array, string $path, string $delimiter = '.') {
return eval("return ".self::getLocationCode($array, $path, $delimiter).";");
}
public static function set(array &$array, string $path, $item, string $delimiter = '.') : void {
//if the last character is a delimiter, allow pushing onto a new or existing array
$add = substr($path, -1) == $delimiter ? '[]': '';
eval(self::getLocationCode($array, $path, $delimiter).$add." = \$item;");
}
public static function unset(array &$array, $path, string $delimiter = '.') : void {
if (is_array($path)) {
foreach($path as $part) {
self::unset($array, $part, $delimiter);
}
}
else {
eval('unset('.self::getLocationCode($array, $path, $delimiter).');');
}
}
public static function isSet(array &$array, $path, string $delimiter = '.') : bool {
if (is_array($path)) {
foreach($path as $part) {
if (!self::isSet($array, $part, $delimiter)) {
return false;
}
}
return true;
}
return eval("return isset(".self::getLocationCode($array, $path, $delimiter).");");
}
private static function getLocationCode(array &$array, string $path, string $delimiter) : string {
$path = rtrim($path, $delimiter); //Trim trailing delimiters
$escapedPathParts = array_map(function ($s) { return str_replace('\'', '\\\'', $s); }, explode($delimiter, $path));
return "\$array['".implode("']['", $escapedPathParts)."']";
}
}
Example usage:
echo '<pre>';
$array = [];
ArrayDot::set($array, 'one.two.three.', 'one.two.three.');
ArrayDot::set($array, 'one.two.three.four.', 'one.two.three.four.');
ArrayDot::set($array, 'one.two.three.four.', 'one.two.three.four. again');
ArrayDot::set($array, 'one.two.three.five.', 'one.two.three.five.');
ArrayDot::set($array, 'one.two.three.direct set', 'one.two.three.direct set');
print_r($array);
echo "\n";
echo "one.two.three.direct set: ".print_r(ArrayDot::get($array, 'one.two.three.direct set'), true)."\n";
echo "one.two.three.four: ".print_r(ArrayDot::get($array, 'one.two.three.four'), true)."\n";
Output:
Array
(
[one] => Array
(
[two] => Array
(
[three] => Array
(
[0] => one.two.three.
[four] => Array
(
[0] => one.two.three.four.
[1] => one.two.three.four. again
)
[five] => Array
(
[0] => one.two.three.five.
)
[direct set] => one.two.three.direct set
)
)
)
)
one.two.three.direct set: one.two.three.direct set
one.two.three.four: Array
(
[0] => one.two.three.four.
[1] => one.two.three.four. again
)

Related

Search array by key branch

I have an array that looks like this:
$array = array (
[level_1] => array (
[level_2] => array (
[level_3] => something
)
),
[level_12] => array (
[level_2] => somethingelse
),
[level_13] => array (
[level_22] => array (
[level_3] => something
)
),
);
The keys or values aren't always unique but the branches are.
And I have a string that looks like this:
$string = 'level_1-level_2-level_3';
Those are the keys for a branch.
And I need to somehow get the value from the array based on that string?
Like this:
$string_array = explode('-', $string);
$array[$string_array[0]][$string_array[1]][$string_array[2]] // something
But since the depth can be different this is not a viable solution...
Try this simple example, no need for a recursive function:
function get_item( $path, $array )
{
$paths = explode( '-', $path );
$result = $array;
foreach ( $paths as $path) {
isset( $result[$path] ) ? $result = $result[$path] : $result = false;
}
return $result;
}
$path = 'level_1-level_2-level_3';
echo get_item( $path, $array );
Try this:
$array = array (
'level_1' => array (
'level_2' => array (
'level_3' => 'something'
)
),
'level_12' => array (
'level_2' => 'somethingelse'
),
'level_13' => array (
'level_22' => array (
'level_3' => 'something'
)
),
);
$string = 'level_1-level_2-level_3';
$keys = explode('-', $string);
echo getItemIterative($keys, $array);
echo "\n";
echo getItemRecursive($keys, $array);
function getItemIterative($keys, $array)
{
$value = null;
foreach ($keys as $key) {
if ($value == null) {
$value = $array[$key];
}
if (is_array($value) && array_key_exists($key, $value)) {
$value = $value[$key];
}
}
return $value;
}
function getItemRecursive($keys, $array)
{
$key = array_shift($keys);
$value = $array[$key];
if (empty($keys)) {
return $value;
} else {
return getItemRecursive($keys, $value);
}
}
Make a $result variable which initially points to the root of the array, and loop through the levels of your $string_array 'til $result points at the leaf you were looking for.
// stuff you already have:
$array = array(...); // your big array
$string = 'level_1-level_2-level_3';
$string_array = explode('-', $string);
// new stuff:
$result = $array;
foreach ($string_array as $level) {
$result = $result[$level];
}
echo $result; // 'something'
Working example: Ideone

Get a value from a multidimensional array using the dot syntax

I have the following array:
$conf = array(
'db' => array(
'server' => 'localhost',
'user' => 'root',
'pass' => 'root',
'name' => 'db',
),
'path' => array(
'site_url' => $_SERVER['SERVER_NAME'],
'site_dir' => CMS,
'admin_url' => conf('path.site_url') . '/admin',
'admin_dir' => conf('path.site_dir') . DS .'admin',
'admin_paths' => array(
'assets' => 'path'
),
),
);
I would like to get a value from this array using a function like so:
/**
* Return or set a configuration setting from the array.
* #example
* conf('db.server') => $conf['db']['server']
*
* #param string $section the section to return the setting from.
* #param string $setting the setting name to return.
* #return mixed the value of the setting returned.
*/
function conf($path, $value = null) {
global $conf;
// We split each word seperated by a dot character
$paths = explode('.', $path);
return $conf[$paths[0]][$paths[1]];
}
But i would like it if the function resolves all dimensions of the array and not just the first two.
Like this
conf('path.admin_paths.assets');
would resolve to
=> $conf['path']['admin_paths']['assets']
How would i do this? Also, how would i make this function if it has another param, would set a value rather than return it?
This function works:
function conf($path, $value = null) {
global $conf;
// We split each word seperated by a dot character
$paths = explode('.', $path);
$result = $conf;
foreach ($paths as $path) {
$result = $result[$path];
}
return $result;
}
Edit:
Add Set:
function conf($path, $value = null) {
global $conf;
// We split each word seperated by a dot character
$paths = explode('.', $path);
if ($value === null) {
// Get
$result = $conf;
foreach ($paths as $path) {
$result = $result[$path];
}
return $result;
}
// Set
if (!isset($conf)) $conf = array(); // Initialize array if $conf not set
$result = &$conf;
foreach ($paths as $i=>$path) {
if ($i < count($paths)-1) {
if (!isset($result[$path])) {
$result[$path] = array();
}
$result = &$result[$path];
} else {
$result[$path] = $value;
}
}
}
I found #Danijel recursive approach a lot cleaner than my initial try. So here's a recursive implementation of the functionality, supporting setting values.
function array_get_by_key(&$array, $key, $value = null) {
list($index, $key) = explode('.', $key, 2);
if (!isset($array[$index])) throw new Exception("No such key: " . $index);
if(strlen($key) > 0)
return array_get_by_key(&$array[$index], $key, $value);
$old = $array[$index];
if ($value !== null) $array[$index] = $value;
return $old;
}
function config($key, $value = null) {
global $CONFIG;
return array_get_by_key(&$CONFIG, $key, $value);
}
Test run:
$CONFIG = array(
'db' => array(
'server' => 'localhost',
'user' => 'root',
'pass' => 'root',
'name' => 'db',
),
'path' => array(
'site_url' => 'localhost',
'site_dir' => 'CMS',
'admin_url' => 'localhost/admin',
'admin_dir' => 'localhost/res/admin',
'admin_paths' => array(
'assets' => 'path'
),
),
);
try {
var_dump(config('db.pass'));
var_dump(config('path.admin_url', 'localhost/master'));
var_dump(config('path.admin_url'));
var_dump(config('path.no_such'));
} catch (Exception $e) {
echo "Error: trying to access unknown config";
}
// string(4) "root"
// string(15) "localhost/admin"
// string(16) "localhost/master"
// Error: trying to access unknown config
function conf($path,$value=null) {
global $conf;
// We split each word seperated by a dot character
$paths = explode('.', $path);
$temp = $conf ;
$ref = &$conf ;
foreach ( $paths as $p )
{
$ref = &$ref[$p] ; // Register the reference to be able to modify $conf var
if ( isset($temp[$p]) )
$temp = $temp[$p] ;
elseif ( $value !== null ) // This key does not exist, and we have a value : time to modify
$ref = $value ;
else // Key does not exist and no value to add
return false ;
}
return $temp ;
}
function conf($path, $value = null) {
global $conf;
$paths = explode('.', $path);
$array = &$conf; // Reference to the config array
foreach ($paths as $k) {
if (!is_array($array)) throw new Exception("No such key: " . $path);
if (!isset($array[$k])) throw new Exception("No such key: " . $path);
// In order to walk down the array, we need to first save the ref in
// $array to $tmp
$tmp = &$array;
// Deletes the ref from $array
unset($array);
// Create a new ref to the next item
$array =& $tmp[$k];
// Delete the save
unset($tmp);
}
$val = $array
if ($value !== null) $array = $value;
return $array
}
(Code inpired by this SO question and Pierre Granger's answer)
As I see it, to get any value from the multidimensional array, recursion is the proper way. Also, you can't use conf() function inside the $conf array before the array is initialized ( the global $conf; will be NULL, eg. not set )
function conf( $path ) {
global $conf;
return recurse( $conf, explode( '.', $path ) );
}
function recurse( $array, $keys ) {
if ( isset( $keys[0] ) && isset( $array[$keys[0]] ) ) {
$array = $array[$keys[0]];
array_shift( $keys );
return recurse( $array, $keys );
} else return is_string( $array ) ? $array : false ;
}
print_r2( conf('path.admin_paths.assets') ); // #str "path"
print_r2( conf('path.admin_paths') ); // #bool false ( path is invalid )
print_r2( conf('path.admin_url') ); // #str "/admin"
print_r2( conf('db.server') ); // #str "localhost"
I have implemented array access class CompositeKeyArray, that hides away the recursion so you can simply get and set nested keys.
Given that class the original problem can be solved like this:
$conf = new CompositeKeyArray($conf);
var_dump($conf[['path', 'admin_paths', 'assets']]); // => string(4) "path"
If you want you can change the value:
$conf[['path', 'admin_paths', 'assets']] = 'new path';
var_dump($conf[['path', 'admin_paths', 'assets']]); // => string(8) "new path"
Or even unset it:
unset($conf[['path', 'admin_paths', 'assets']]);
var_dump(isset($conf[['path', 'admin_paths', 'assets']])); // => bool(false)
Here is working demo.

multilevel array from a config string [duplicate]

I have the next INI file:
a.b.c = 1
a.b.d.e = 2
I am parsing this file using parse_ini_file. And it returns:
array(
'a.b.c' => 1,
'a.b.d.e' => 2
)
But I want to create a multidimensional array. My outout should be:
array(
'a' => array(
'b' => array(
'c' => 1,
'd' => array(
'e' => 2
)
)
)
)
Thank you in advance.
This is how I see it:
<?php
class ParseIniMulti {
public static function parse($filename) {
$ini_arr = parse_ini_file($filename);
if ($ini_arr === FALSE) {
return FALSE;
}
self::fix_ini_multi(&$ini_arr);
return $ini_arr;
}
private static function fix_ini_multi(&$ini_arr) {
foreach ($ini_arr AS $key => &$value) {
if (is_array($value)) {
self::fix_ini_multi($value);
}
if (strpos($key, '.') !== FALSE) {
$key_arr = explode('.', $key);
$last_key = array_pop($key_arr);
$cur_elem = &$ini_arr;
foreach ($key_arr AS $key_step) {
if (!isset($cur_elem[$key_step])) {
$cur_elem[$key_step] = array();
}
$cur_elem = &$cur_elem[$key_step];
}
$cur_elem[$last_key] = $value;
unset($ini_arr[$key]);
}
}
}
}
var_dump(ParseIniMulti::parse('test.ini'));
It's actually quite simple, you only need to change the format of the array you already have by exploding it's key:
$ini_preparsed = array(
'a.b.c' => 1,
'a.b.d.e' => 2
);
$ini = array();
foreach($ini_preparsed as $key => $value)
{
$p = &$ini;
foreach(explode('.', $key) as $k)
$p = &$p[$k];
$p = $value;
}
unset($p);
print_r($ini);
Output:
Array
(
[a] => Array
(
[b] => Array
(
[c] => 1
[d] => Array
(
[e] => 2
)
)
)
)
See as well: String with array structure to Array.
Have a look at the Zend_Config_Ini class. It does what you want, you can use it standalone (without the rest of Zend Framework) and as a bonus it supports section inheritance.
With the toArray method you can create an array from the config object.
Take a look at PHProp.
Similar to Zend_Config_Ini, but you can refer to a key in your config like ${key}
It's a my class for parsing config ini files to a multidimensional array:
class Cubique_Config {
const SEPARATOR = '.';
private static $_data = null;
public static function get() {
if (is_null(self::$_data)) {
$commonIniFile = APP . '/config' . '/common.ini';
$envIniFile = APP . '/config' . '/' . ENV . '.ini';
if (!file_exists($commonIniFile)) {
throw new Exception('\'' . $commonIniFile . '\' config file not found');
}
if (!file_exists($envIniFile)) {
throw new Exception('\'' . $envIniFile . '\' config file not found');
}
$commonIni = parse_ini_file($commonIniFile);
$envIni = parse_ini_file($envIniFile);
$mergedIni = array_merge($commonIni, $envIni);
self::$_data = array();
foreach ($mergedIni as $rowKey => $rowValue) {
$explodedRow = explode(self::SEPARATOR, $rowKey);
self::$_data = array_merge_recursive(self::$_data, self::_subArray($explodedRow, $rowValue));
}
}
return self::$_data;
}
private static function _subArray($explodedRow, $value) {
$result = null;
$explodedRow = array_values($explodedRow);
if (count($explodedRow)) {
$firstItem = $explodedRow[0];
unset($explodedRow[0]);
$result[$firstItem] = self::_subArray($explodedRow, $value);
} else {
$result = $value;
}
return $result;
}
}

How to filter an array by a part of key?

I have an array like this:
Array(
[id-1] => N
[nm-1] => my_val_01;
[id-48] => S
[nm-48] => my_val_02;
[id-52] => N
[nm-52] => my_val_03;
[id-49] => N
[nm-49] => my_val_04;
[id-50] => N
[nm-50] => my_val_05;
}
and would like to filter by part of the key. In this case I would like to have all keys that have "id-", and to result in this:
Array(
[id-1] => N
[id-48] => S
[id-52] => N
[id-49] => N
[id-50] => N
}
Can anyone help?
foreach (array_keys($array) as $key) {
if (!preg_match('/^id-\d+/', $key)) {
unset($array[$key]);
}
}
this way you can do.
$arr = Array(
[id-1] => N
[nm-1] => my_val_01;
[id-48] => S
[nm-48] => my_val_02;
[id-52] => N
[nm-52] => my_val_03;
[id-49] => N
[nm-49] => my_val_04;
[id-50] => N
[nm-50] => my_val_05;
};
$new = array();
foreach($arr as $key => $value){
if(stripos($key, "id-") !== false){
$new[$key] = $value;
}
}
//so $new is your required array here
Use the following (untested):
function filter($key) {
return substr($key, 0, 3) == 'id-';
}
$keys = array_filter(array_keys($array), 'filter');
if(empty($keys))
$array = array();
else
$array = array_intersect_key(array_flip($keys), $input);
You can write a little function that works analog to array_filter:
<?php
$a = array(
'id-1' => 'N', 'nm-1' => 'my_val_01', 'id-48' => 'S', 'nm-48' => 'my_val_02', 'id-52' => 'N',
'nm-52' => 'my_val_03', 'id-49' => 'N', 'nm-49' => 'my_val_04', 'id-50' => 'N', 'nm-50' => 'my_val_05'
);
$b = array_filter_key($a, function($e) {
return 0===strpos($e, 'id-');
});
var_dump($b);
function array_filter_key($source, $callback) {
// TODO: check arguments
$keys = array_keys($source);
$keys = array_filter($keys, $callback);
return ( 0===count($keys) ) ?
array()
:
array_intersect_key(array_flip($keys), $source)
;
}
prints
array(5) {
["id-1"]=>
int(0)
["id-48"]=>
int(2)
["id-52"]=>
int(4)
["id-49"]=>
int(6)
["id-50"]=>
int(8)
}
Try with:
$input = array( /* your data */ );
$output = array();
$pattern = 'id-';
foreach ( $input as $key => $value ) {
if ( strpos($key, $pattern) === 0 ) { # Use identical not equal operator here
$output[$key] = $value;
}
}
Answers, on the internet, that utilize array_intersect_key are INcorrect.
They Filter Right, but Output "filtered keys index" values instead of input array values.
Here is a fixed version
/**
* Filter array keys by callback
*
* #param array $input
* #param $callback
* #return NULL|unknown|multitype:
*/
function array_filter_keys($input, $callback)
{
if (!is_array($input)) {
trigger_error('array_filter_key() expects parameter 1 to be array, ' . gettype($input) . ' given', E_USER_WARNING);
return null;
}
if (empty($input)) {
return $input;
}
$filteredKeys = array_filter(array_keys($input), $callback);
if (empty($filteredKeys)) {
return array();
}
$input = array_intersect_key($input, array_flip($filteredKeys));
return $input;
}
If you're using the latest PHP version:
$filtered_arr = array_filter($arr, 'filter_my_array', ARRAY_FILTER_USE_KEY);
function filter_my_array( $key ) {
return preg_match("/^id-\d+/", $key);
}

INI file to multidimensional array in PHP

I have the next INI file:
a.b.c = 1
a.b.d.e = 2
I am parsing this file using parse_ini_file. And it returns:
array(
'a.b.c' => 1,
'a.b.d.e' => 2
)
But I want to create a multidimensional array. My outout should be:
array(
'a' => array(
'b' => array(
'c' => 1,
'd' => array(
'e' => 2
)
)
)
)
Thank you in advance.
This is how I see it:
<?php
class ParseIniMulti {
public static function parse($filename) {
$ini_arr = parse_ini_file($filename);
if ($ini_arr === FALSE) {
return FALSE;
}
self::fix_ini_multi(&$ini_arr);
return $ini_arr;
}
private static function fix_ini_multi(&$ini_arr) {
foreach ($ini_arr AS $key => &$value) {
if (is_array($value)) {
self::fix_ini_multi($value);
}
if (strpos($key, '.') !== FALSE) {
$key_arr = explode('.', $key);
$last_key = array_pop($key_arr);
$cur_elem = &$ini_arr;
foreach ($key_arr AS $key_step) {
if (!isset($cur_elem[$key_step])) {
$cur_elem[$key_step] = array();
}
$cur_elem = &$cur_elem[$key_step];
}
$cur_elem[$last_key] = $value;
unset($ini_arr[$key]);
}
}
}
}
var_dump(ParseIniMulti::parse('test.ini'));
It's actually quite simple, you only need to change the format of the array you already have by exploding it's key:
$ini_preparsed = array(
'a.b.c' => 1,
'a.b.d.e' => 2
);
$ini = array();
foreach($ini_preparsed as $key => $value)
{
$p = &$ini;
foreach(explode('.', $key) as $k)
$p = &$p[$k];
$p = $value;
}
unset($p);
print_r($ini);
Output:
Array
(
[a] => Array
(
[b] => Array
(
[c] => 1
[d] => Array
(
[e] => 2
)
)
)
)
See as well: String with array structure to Array.
Have a look at the Zend_Config_Ini class. It does what you want, you can use it standalone (without the rest of Zend Framework) and as a bonus it supports section inheritance.
With the toArray method you can create an array from the config object.
Take a look at PHProp.
Similar to Zend_Config_Ini, but you can refer to a key in your config like ${key}
It's a my class for parsing config ini files to a multidimensional array:
class Cubique_Config {
const SEPARATOR = '.';
private static $_data = null;
public static function get() {
if (is_null(self::$_data)) {
$commonIniFile = APP . '/config' . '/common.ini';
$envIniFile = APP . '/config' . '/' . ENV . '.ini';
if (!file_exists($commonIniFile)) {
throw new Exception('\'' . $commonIniFile . '\' config file not found');
}
if (!file_exists($envIniFile)) {
throw new Exception('\'' . $envIniFile . '\' config file not found');
}
$commonIni = parse_ini_file($commonIniFile);
$envIni = parse_ini_file($envIniFile);
$mergedIni = array_merge($commonIni, $envIni);
self::$_data = array();
foreach ($mergedIni as $rowKey => $rowValue) {
$explodedRow = explode(self::SEPARATOR, $rowKey);
self::$_data = array_merge_recursive(self::$_data, self::_subArray($explodedRow, $rowValue));
}
}
return self::$_data;
}
private static function _subArray($explodedRow, $value) {
$result = null;
$explodedRow = array_values($explodedRow);
if (count($explodedRow)) {
$firstItem = $explodedRow[0];
unset($explodedRow[0]);
$result[$firstItem] = self::_subArray($explodedRow, $value);
} else {
$result = $value;
}
return $result;
}
}

Categories