Bear with me if this is unclear; I have trouble fully wrapping my head around this (hence why I am here to ask for help).
I have an array that looks like this:
Array
(
[DimA1] => Array
(
[DimB1] => Array
(
[DimC1] => Array
(
[value1] => 13708
[value2] => 4.5
)
[DimC2] => Array
(
[value1] => 1846
[value2] => 15.8
)
)
[DimB2] => Array
(
[DimC1] => Array
(
[value1] => 18166
[value2] => 6.4
)
)
[DimA2] => Array
(
....... etc
I need to step through this array and when I get to value1 and value2, I need to do some database inserts. At this point in time, I need to be aware of just which arrays I'm currently stepped through and use their key name as part of my database inserts.
My current solution looks like this:
public function recurseCounts($array,$dims = array()) {
foreach ($array as $key => $value) {
$dims[] = $key;
if (isset($value['value1']) || isset($value['value2'])) {
print_r($value); // For debugging...
print_r($dims); // For debugging...
// DB Logic to insert dimensions in to DB here
// DB Logic to insert values in to DB here
array_pop($dims);
} else {
$this->recurseCounts($value,$dims);
}
}
}
This works up until the point the loop hits DimB2, that's where things start getting whacky.
Any ideas on how to solve this?