Page 1 of 1

multidimensional array and storing locations of values

Posted: Sun Feb 07, 2010 12:41 pm
by cone13cone
I have an object which creates a multidimensional array. I would like to be able to store the locations of the values in a separate array. Kinda like a road map of the original array, so when I update via JSON my script will know where to look for the specified value inside of the updated array.

$array = ['first'][1]['second'][0]['item'] = 'some item to be updated';

What I need to store is the ['first'][1]['second'][0]['item'] which is the location of 'some value to be updated';

Ideally after my array is completed I would like to be able to loop through it and store the location of each value like above.

Any ideas or suggestions would be appreciated.

Edit: also what would be the best way to store the location, Im assuming a string.

Re: multidimensional array and storing locations of values

Posted: Sun Feb 07, 2010 1:59 pm
by limitdesigns
You can do a series of foreach loops that parse through each of your arrays within the main array.

Example:

Code: Select all

 
$array = array(your_array);
// First dimension
foreach($array as $key=>$value) {
     // Second dimension
     foreach($value as $key2=>$value2) {
          do_something();
     }
}