新建二个文件.data下.index1.php,items1.php,把要替换的数据摘取出来.
1.文件
index1.php
<?php
return [
[
‘id’ => 1,
‘title’ => ‘切实做好高风险岗位从业人员疫情防控。’,
‘content’ => ‘切实做好高风险岗位从业人员疫情防控。’,
‘url’=>’https://www.php.cn‘
],
[
‘id’ => 2,
‘title’ => ‘切实做好高风险岗位从业人员疫情防控。’,
‘content’ => ‘切实做好高风险岗位从业人员疫情防控。’,
‘url’=>’https://www.php.cn‘
],
[
‘id’ => 3,
‘title’ => ‘切实做好高风险岗位从业人员疫情防控。’,
‘content’ => ‘切实做好高风险岗位从业人员疫情防控。’,
‘url’=>’https://www.php.cn‘
],
];
2.文件
items1.php
[ ‘id’ => 1,
‘title’ => ‘最新产品1’,
‘content’ => ‘最新产品1’,
‘url’=>’https://www.php.cn‘
],
[ ‘id’ => 2,
‘title’ => ‘最新产品2’,
‘content’ => ‘最新产品2’,
‘url’=>’https://www.php.cn‘
],
[ ‘id’ => 3,
‘title’ => ‘最新产品3’,
‘content’ => ‘最新产品3’,
‘url’=>’https://www.php.cn‘
],
3.文件
index.php
<main>
<div class="news">
<h3>新闻列表</h3>
<?php foreach ($index1 as $value) ?>
<a href="<?=$index1['url']?"><?=$index1[‘title’]?></a>
<?php endforeach ?>
</div>
<div>
<h3>产品列表</h3>
<?php foreach ($items as $item) ?>
<a href="<?=$items1['url']?"><?=$items1[‘title’]?></a>
<?php endforeach ?>
</div>
</main>