Blogger Information
Blog 25
fans 0
comment 0
visits 9274
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1124使用流程控制替换语法,将演示网站的首页和产品页进行动态替换
P粉114035831
Original
335 people have browsed it

新建二个文件.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>

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!