0

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 ?>

1 Answer 1

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.