If you have a multidimensional array you'll need to use a recursive function.
an example might be this
function unfoldArray($array,$output = array()) {
if(is_object($array)) {
$array = (array)$array;
}
foreach($array as $key => $value) {
if(is_array($value) || is_object($value)) {
//$output[] = $key;
$output = unfoldArray($value,$output);
} else {
$output[] = $value;
}
}
return $output;
}
the above function, given an array like
$array = array(
"one",
"two",
"three" => array("A","B","C"),
"four" => array("X","Y","Z"),
"five",
"six" => array(
"sub_one",
"sub_two",
"sub_three" => array("sub_A","sub_B","sub_C")
),
"seven"
);
$output = unfoldArray($array);
would return a flat array like this
// $output
[
"one",
"two",
"A",
"B",
"C",
"X",
"Y",
"Z",
"five",
"sub_one",
"sub_two",
"sub_A",
"sub_B",
"sub_C",
"seven"
]
you may notice that values "three" and "six" are omitted from the result array because they are key, but if you wan to include them just uncomment the line //$output[] = $key; in the function.
Once you have this array you may just loop with a foreach.
This might not be exactly what you need, but should give you a direction to follow.