my question is how can i get all values from determined level of some array, i have this array:
array (size=4)
'Azul' =>
array (size=2)
'128GB' =>
array (size=2)
'Cristal' => string 'Cristal' (length=7)
'Plastico' => string 'Plastico' (length=8)
'64GB' =>
array (size=1)
'Cristal' => string 'Cristal' (length=7)
'Blanco' =>
array (size=2)
'32GB' =>
array (size=1)
'Plastico' => string 'Plastico' (length=8)
'64GB' =>
array (size=1)
'Madera' => string 'Madera' (length=6)
'Dorado' =>
array (size=1)
'64GB' =>
array (size=1)
'Plastico' => string 'Plastico' (length=8)
'Verde' =>
array (size=1)
'64GB' =>
array (size=1)
'Madera' => string 'Madera' (length=6)
And i want get the first level with this recursive function, but i cant find more deeper than 2 levels for example i need the first level and i get:
Azul, Blanco, Dorado, Verde
But i need the second level of Azul i get: 128GB, 64GB
The questions is, if i need the 3rd level of Azul and 64GB, what can i do to get this, having the keys Azul and 64GB or level 3.
My recursive but buggy function is this:
function recursive($array, $level, $itemLVL)
{
foreach ($array as $key => $value) {
//If $value is an array.
if (is_array($value)) {
//We need to loop through it.
if ($level == $itemLVL) {
//echo "<br> Key: $key - Nivel:$level $itemLVL";
echo "<option value='$key'>$key</option>";
}
recursive($value, $level + 1, $itemLVL);
} elseif ($level == $itemLVL) {
echo "<option value='$key'>$key</option>";
}
}
}
Azuland64GB?