简体   繁体   中英

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 ?>
<?php foreach ($art["places"] as $value): ?>
<?= $value ?>
<?php endforeach; ?>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM