简体   繁体   English

如何输出数组中的值?

[英]How to output values in array?

Hello I have the following variable in my PHP:您好,我的 PHP 中有以下变量:

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

I am just trying to output 'places' only into my HTML code.我只是想将“位置”仅输出到我的 HTML 代码中。 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"];你应该循环 $art["places"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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