php小案例:信息收集表、时间戳练习、将1-100之间所有的奇数存入数组、图书信息表、扑克牌小游戏

信息手机表(运用Bootstrap样式):

<html>
	<head>
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
	</head>
	<body>
		<center><h3>学生信息表</h3></center>
		<table class="table table-bordered table-striped table-hover">
			
		
		<?php
$stus=[
    [
       "id"=>"1001",
       "name"=>"刘德华",
       "sex"=>"男",
       "mobile"=>"17324587539"
    ],
    [
       "id"=>"1002",
       "name"=>"郭富城",
       "sex"=>"男",
       "mobile"=>"17324765984"
    ],
    [
       "id"=>"1003",
       "name"=>"黎明",
       "sex"=>"男",
       "mobile"=>"17564907597"
    ],
    [
       "id"=>"1004",
       "name"=>"张学友",
       "sex"=>"男",
       "mobile"=>"17325437637"
    ],
];
for($i=0;$i<4;$i++){
	echo "<tr>";
	echo "<td>".$stus[$i]["id"]."</td>";
	echo "<td>".$stus[$i]["name"]."</td>";
	echo "<td>".$stus[$i]["sex"]."</td>";
	echo "<td>".$stus[$i]["mobile"]."</td>";
	echo "<td>";
		echo "<button class='btn btn-primary'>删除</button>";
		echo "&nbsp;&nbsp;<button class='btn btn-danger'>修改</button>";
	echo "</td>";
	echo "</tr>";
}
?>
</table>
	</body>
</html>

结果图:

 时间戳练习:

<?php
	$sjc=mktime(12,30,0,5,17,2022);
	echo $sjc;
    echo "<hr>";
    echo "时间戳转年月日:".date("Y-m-d H:i:s",$sjc);
    echo "<hr>";
    echo time();
    echo "<hr>";
    echo "北京时间:".date("Y-m-d H:i:s",time());
    echo "<hr>";
    echo "当前日期".date("Y-m-d");
    echo "<hr>";
    echo "当前时间".date("H:i:s");
    
    echo "<hr>";
    echo "2022-5-27时转成时间戳:".strtotime(date("Y-m-d H:i:s"));
    echo "<hr>";
    echo "此时间后一天的时间戳:".date("Y-m-d",strtotime("+1 week"));
    echo "<hr>";
    $s=microtime();
    echo "<hr>";
    echo md5($s);
?>

结果图:

将1-100之间所有的奇数存入数组:

<?php
echo "<hr>";
$arr=[];
$arr[]=123;
$arr[]=456;
print_r($arr);
echo "<hr>";
// 请将1-100之间所有的奇数存入数组
$x=[];
for($i=1;$i<=100;$i++){
    if($i%2!=0){
        $x[]=$i;
    }
}
print_r($x);
?>

结果图:

 图书信息表:

<html>
	<head>
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
	</head>
	<body>
		<center>
			<h1>图书信息列表</h1>
			<hr />
		</center>
		<table class="table table-bordered table-striped table-hover">
		<?php
			 $books=[
			 "no1"=>["isbn"=>"456-765-4563",
             "name"=>"关于不要在机房里面吃饭的说明",
             "price"=>2000,
             "author"=>"教务处"
             ],
             "no2"=>["isbn"=>"456-765-1543",
             "name"=>"大学生基本常识",
             "price"=>1000,
             "author"=>"教务处"
             ],
             "no3"=>["isbn"=>"456-765-7698",
             "name"=>"做人的道理",
             "price"=>3500,
             "author"=>"教务处"
             ],
             ];
             foreach($books as $r){
             ?>
             <tr>
             <td><?=$r["isbn"]?></td>
             <td><?=$r["name"]?></td>
             <td><?=$r["price"]?></td>
             <td><?=$r["author"]?></td>
             <td>
             	<button class="btn btn-danger btn-sm">删除</button>
             	<button class="btn btn-primary btn-sm">修改</button>
             </td>
             </tr>
             <?php
             }
    
        ?>
        </table>
	</body>
</html>

结果图:

 扑克牌小游戏:

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
	.pai{
		width:60px;
		height: 85px;
	}
	</style>
</head>
<body>
<?php
$ps=[];
for($i=1;$i<=54;$i++){
	$ps[]=$i;
}
echo"<br>一开始一副新牌如下:<br>";
print_r($ps);
echo "<br>玩家1的牌:<br>";
$p1=array_rand($ps,18);
sort($p1);
$x=[];
foreach($p1 as $i){
	$x[]=$ps[$i];
	$img="./images02/".$ps[$i].".jpg";
	echo "<img src='".$img."' class='pai'>";
}
//把这18张牌从54张牌中删除
$ps=array_diff($ps,$x);
echo "<br>剩下的36张牌:<br>";
print_r($ps);

echo "<br>玩家2的牌:<br>";
$p2=array_rand($ps,18);
sort($p2);
$x=[];
foreach($p2 as $i){
	$x[]=$ps[$i];
	$img="./images02/".$ps[$i].".jpg";
	echo "<img src='".$img."' class='pai'>";
}

//把玩家2的18张牌从36张牌中删除
$ps=array_diff($ps,$x);
echo "<br>剩下的18张牌:<br>";
print_r($ps);

echo "<br>玩家3的牌:<br>";
foreach($ps as $i){
	$img="./images02/".$i.".jpg";
	echo "<img src='".$img."' class='pai'>";
}
?>
</body>
</html>

结果图:

猜你喜欢

转载自blog.csdn.net/m0_69034993/article/details/127235219