I'm currently building an array from a sql query
$displayResult = $mysqlConn->query($getDisplays);
$displayNames = array();
foreach($displayResult as $subArray) {
if(!array_key_exists($subArray['location_name'], $displayNames)) {
$displayNames[$subArray['location_name']] = array();
}
$displayNames[$subArray['location_name']][] = $subArray['display_name'];
}
print_r($displayNames);
And it prints like:
Array
(
[Office 1] => Array
(
[0] => lobby
[1] => break room
)
[Office 2] => Array
(
[0] => lobby
[1] => break room
)
But for some reason when I loop and try to echo the array key as a header and the children as links, it just dumps the word 'array'
<?php foreach($displayNames as $key => $displayName):?>
<h2><?php echo $key; ?></h2>
<a><h4><?php echo $displayName; ?></h4></a>
<?php endforeach;?>
I tried dumping by index but it's blank. Do I need another nested foreach to get each child?