mercredi 24 février 2016

Foreach loop and multi array echo

I am having some difficulty echo'ing an multidimensional array.

Here is the array dump:

$_SESSION['cart']: Array
(
    [SW] => Array
        (
            [mID] => SW
            [mday] => Mon
            [mtime] => 9:00pm
            [seat] => Array
                (
                    [sa] => 8
                    [sp] => 5
                    [sc] => 2
                    [b2] => 3
                )

            [price] => $200.00
        )
)

and here is my echo loop:

<?php foreach ($_SESSION['cart'] as $booking) { ?>
    <section>
        <?php foreach ($booking as $key => $value) { ?>
            <ul>
                <li>
                    <label><?php echo $key ?>:</label>
                    <span><?php echo $value?></span>
                </li>
            </ul>
         <?php } ?>
    </section>
<?php } ?>

I keep hitting an error when the loop gets to [seat].

How can I have it loop through the nested array?

Thanks for the help!

Aucun commentaire:

Enregistrer un commentaire