<?php
//声明一个php数组
$arr = [
'吃饭',
'睡觉',
'打游戏',
'追剧',
'发呆'
];
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>小眼睛0802作业</title>
</head>
<body>
<h2><?php echo '你最喜欢做什么?'?></h2>
<!-- 使用foreach遍历数组-->
<ol>
<? foreach ($arr as $v):?>
<li><a><? echo $v?></a></li>
<? endforeach;?>
</ol>
<!-- 使用for循环遍历数组-->
<ul>
<? for ($i=0;$i<count($arr);$i++){?>
<li><a><? echo $arr[$i]?></a></li>
<?}?>
</ul>
<script>
// 声名一个js数组
var arr = [
'吃饭',
'睡觉',
'打游戏',
'追剧',
'发呆'
];
// 前端不是很好就这样输出吧
for (i=0; i<arr.length; i++){
alert(arr[i]);
}
</script>
</body>
</html>
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!