I have set up a multidimensional array in PHP like this:
$contents = array(
"Header1" => array(
"Section 1" => array (
"Description1",
"Notes1",
),
"Gap" => "Gap",
"Section 2" => array (
"Description2",
"Notes2",
),
"Gap" => "Gap",
"Section 3" => array (
"Description3",
"Notes3",
),
),
);
then I loop through this array as follows:
foreach ($contents as $header => $section) {
foreach ($section as $title => $details) {
echo $title."<br>";
}
}
The output will be:
Section1
Gap
Section2
Section3
Why isn’t the second “Gap” showing?
Thanx
Because you can’t have duplicate array keys. The second one overwrites the first.
Use
Gap2or something for your next array key. Or, better yet, nest it: