I have a read only multidimensional associative array I need to extract specific values from to generate output with some of the values.
The array looks like this:
array (
'Dogs' =>
array (
0 =>
array (
'Name' => 'Big Dogs',
'ID' => '32',
'Brown dogs' =>
array (
0 =>
array (
'Name' => '4 legged dogs',
'Retrievers' =>
array (
0 =>
array (
'Name' => 'Fido',
'ID' => '11',
'Owner' => 'Billy',
'IsaBiter' => true,
),
),
),
1 =>
array (
'Name' => '3 legged dogs',
'Retrievers' =>
array (
0 =>
array (
'Name' => 'Spot',
'ID' => '12',
'Owner' => 'Sally',
'IsaBiter' => false,
),
),
),
etc..
And a nested foreach loop that runs through the array that can print all values of the array as follows:
echo "<ul>";
foreach($myArray as $arr1 => $val1) {
foreach($val1 as $arr2 => $val2) {
foreach($val2 as $val3) {
echo "<li>" . $val3 . "<ul>";
foreach($val3 as $arr4 => $val4) {
foreach($val4 as $arr5 => $val5) {
echo "<li>" . $val5;
foreach($val5 as $arr6 => $val6) {
//echo $val6;
foreach($val6 as $arr7 => $val7) {
echo $val7 . "<br />"; //dumps the details
}
echo "</li>";
}
}
}
echo "</ul>";
echo "</li>";
}
}
}
Ideally I would like to be able to 1) exclude values I do not want show (ID, certain array level names etc, currently it shows all) and 2) display specific ones (ie Name, owner, IsaBiter) so I can format the results cleaner, similar to this:
Big Dogs
Brown Dogs
Retrievers
Name: Fido
Owner: Billy
IsaBiter: true
Name: Spot
Owner: Sally
IsaBiter: false