I have a multidimensional array that is being built pulled from a file structure.
I am trying to use this array to create dynamic HTML tables based on the key for each item. The script I am using to pull the file structure is making each folder into the keys of the array.
So the array is outputting like this:
Array(
[english] => Array
(
[term1] => Array
(
[circ] => Array
(
[Unit1] => Array
(
[0] => file.zip
)
[Unit2] => Array
(
[0] => file.zip
)
[Unit3] => Array
(
[0] => file.zip
)
[Unit4] => Array
(
[0] => file.zip
)
)
[type] => Array
(
[Unit1] => Array
(
[0] => file.zip
)
[Unit2] => Array
(
[0] => file.zip
)
[Unit3] => Array
(
[0] => file.zip
)
[Unit4] => Array
(
[0] => file.zip
)
)
)
[term2] => Array
(
[circ] => Array
(
[Unit1] => Array
(
[0] => file.zip
)
[Unit2] => Array
(
[0] => file.zip
)
[Unit3] => Array
(
[0] => file.zip
)
[Unit4] => Array
(
[0] => file.zip
)
)
[type] => Array
(
[Unit1] => Array
(
[0] => file.zip
)
[Unit2] => Array
(
[0] => file.zip
)
[Unit3] => Array
(
[0] => file.zip
)
[Unit4] => Array
(
[0] => file.zip
)
)
)
)
)
What I am trying to output is a page with a table that will use the keys something like this.
title = engligh
heading 1 = term1
heading 2 = circ
content 1 =
content 2 = Unit1
content 2 = Unit2
link = file.zip
{title}
<table class="table table-hover">
<thead>
<th>{heading1}</th>
<th>{heading2}</th>
</thead>
<tbody>
<tr>
<td>{content1}</td>
<td><a href="{link}">{content2}</a></td>
</tr>
</tbody>
</table>
I have not used PHP in over 5 years and to be honest was never very good at it in the first place, I have simply been thrown in the deep end at work and need some help to make this happen so any help given is very much appreciated!
Edit
So I have created a function that is pulling the first 2 level of keys from the array, however when I added in a third level it is just repeating the second level. I think recursive is more along the lines of what I need however I can not get my head around that.
function recursive(array $array){
foreach($array as $key => $value){
echo $key, '<br>';
//If $value is an array.
if(is_array($value)){
//We need to loop through it.
foreach($value as $key1 => $value1) {
echo ' - ' . $key1, '<br>';
//if $value is an array.
if(is_array($value1)){
foreach ($value1 as $key2 => $value2) {
echo ' - ' . $key2, '<br>';
}
}else{
echo ' - ' . $key1, '<br>';
}
}
} else{
//It is not an array, so print it out.
echo $key, '<br>';
}
}
}
Can anyone tell me where I am going wrong with getting so many levels out of this function?