php foreach代码片段
<?php
$arr = [
[
'id'=>1,
'title'=>'河南暴雨致302人遇难50人失踪'
],
[
'id'=>2,
'title'=>'国产疫苗对Delta有用吗?钟南山回应'
],
[
'id'=>3,
'title'=>'#郎平回应不再执教#'
]
];
?>
<ul>
<?php foreach($arr as $item): ?>
<li style="display:flex;align-items:center">
<span style="margin-right: 5px;"><?php echo $item['id'] ?></span>
<a href=""><?php echo $item['title'] ?>
</a>
</li>
<?php endforeach ?>
</ul>
js forEach代码片段
<script>
const arr = [{
id: 1,
title: '河南暴雨致302人遇难50人失踪'
}, {
id: 2,
title: '国产疫苗对Delta有用吗?钟南山回应'
}, {
id: 3,
title: '#郎平回应不再执教#'
}];
arr.forEach(item => {
console.log(`${item.id} ${item.title}`);
})
</script>