我有一個簡單的數組:回聲數組的鍵:URL和標題
Array
(
[url] => http://localhost/theme/wp-content/uploads/2017/08/img2.png
[caption] => title text test
)
但我沒有收到關於在foreach權回聲:
<?php foreach ($imgs as $imgurl) { ?>
<input name="my_image[url]" type="hidden" value="<?php echo $imgurl[url];?>"/>
<input name="my_image[caption]" type="text" value="<?php echo $imgurl[caption];?>">
<?php
};
?>
警告:非法字符串偏移'字幕'在線
不需要'foreach'。只需使用'$ imgs [「url」]'和'$ imgs [「caption」]' –
@SahilGulati僅僅是一個例子,我在真實數組中有更多的數據,有更多的url和標題 – Gislef
你錯過了''''雙引號在'$ imgurl [caption]'中,將其改爲'$ imgurl [「caption」]'並且使用'isset' –