JinkyBu2
JinkyBu2

Reputation: 51

How to output values in array?

Hello I have the following variable in my PHP:

$art= [ 
        'places' => ['America','Paris','Italy','Japan'],
        'photographer' => ['Samantha','Hannah','David','Albert'],
    ];

I am just trying to output 'places' only into my HTML code. Keep getting "Illegal String Offset" warning.

Why is my following code not working?

<?php foreach($art as $value): ?> 
      <?= $value['places'] ?>
    <?php endforeach ?>

Upvotes: 0

Views: 35

Answers (1)

Jerry
Jerry

Reputation: 333

<?php foreach ($art["places"] as $value): ?>
<?= $value ?>
<?php endforeach; ?>

you should loop the $art["places"];

Upvotes: 1

Related Questions