Blogger Information
Blog 27
fans 0
comment 0
visits 43518
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
is_array()判断循环输出电影网站栏目和子栏目_201909221036
xingzhi的博客
Original
894 people have browsed it

php先创建相应的变量和数组


实例

<?php 

	$title = '简单电影网站实战';
	$copyright = 'php中文网';
	
	$nav = [
		'国产好剧',
		'欧美猛片',
		'日韩新片'
	];
	$movie = [
		'gc' => '国产好剧',
			[
				'倚天屠龙记',
				'都挺好',
				'如果可以这样爱'

			],
		'om' => '欧美猛片',
			[
				'复仇者联盟4',
				'波西米亚狂想曲',
				'阿丽塔'

			],
		'rh' => '日韩新片',
			[
				'情书',
				'天空之城',
				'龙猫'

			],
	]
 ?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

html网站简单案例

is_array()判断$movie中是否是数组,如果是则foreach再循环输出子栏目,否则直接输出栏目

注意:

子栏目循环要包含在<ol></ol>,


实例

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" href="/static/css/style.css">
		<title><?php echo $title ?></title>
		<link rel="stylesheet" href="static/css/style.css">
	</head>
	<body>
		<!--头部导航-->
		<div class="header">
			<ul class="nav">
				<li><a href="">首页</a></li>
				<?php 
					foreach ($nav as $key => $value) {
						echo '<li><a href="">'.$value.'</a></li>';
					}
				 ?>
			</ul>
		</div>
		<!--国产原创-->
		<?php 
			foreach ($movie as $key => $value) {
				if (is_array($value)) {
					echo '<ol>';
					foreach ($value as $k => $v) {
						
						echo '<li><a href="#">'.$v.'</a></li>';
					}
					echo '</ol>';
				}else{
					echo '<h2>'.$value.'</h2>';
				}

			}	
		 ?>
		<!--底部版权-->
		<div class="footer">
			<p class="copyright"><?php echo $copyright ?> © 版权所有</p>
		</div>
	</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

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!