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.
multidimensional array and storing locations of values
Moderator: General Moderators
-
cone13cone
- Forum Newbie
- Posts: 24
- Joined: Fri Mar 20, 2009 8:32 pm
-
limitdesigns
- Forum Commoner
- Posts: 25
- Joined: Sat Feb 06, 2010 9:05 pm
Re: multidimensional array and storing locations of values
You can do a series of foreach loops that parse through each of your arrays within the main array.
Example:
Example:
Code: Select all
$array = array(your_array);
// First dimension
foreach($array as $key=>$value) {
// Second dimension
foreach($value as $key2=>$value2) {
do_something();
}
}