How do I access the first level key of a two-dimensional array using a foreach loop?
I have a $places array like this:
[Philadelphia] => Array ( [0] => Array ( [place_name] => XYX [place_id] => 103200 [place_status] => 0 ) [1] => Array ( [place_name] => YYYY [place_id] => 232323 [place_status] => 0 ) This is my view code that loops over the array:
<?php foreach($places as $site): ?> <h5><?=key($site)?></h5> <?php foreach($site as $place): ?> <h6><?=$place['place_name']?></h6> <?php endforeach?> <?php endforeach ?> Where I call key($site), I want to get Philadelphia, but I am just getting place_name from each row.