我正在努力让这个网站练习我的编程。
<html>
<title>VidVoter</title>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<div id="welcome">Welcome to VidVoter!</div>
<a href="file://localhost/Users/alihashemi/Desktop/vidvoter.html">
<div id="vote1">Vote for this video</div>
</a>
<a href="file://localhost/Users/alihashemi/Desktop/vidvoter.html">
<div id="vote2">Vote for this video</div>
</a>
</head>
<?php
$videos = array("xrCTiImIWk4" , "WCpfVPY4J6I" , "__2ABJjxzNo" , "y7tI1E6kp0o" , "-NSL_DgwCYw");
$rand = array_rand($videos);
$rand_key = isset($_GET['id']) ? $_GET['id'] : $rand;
?>
<p>
<h1><iframe width="560" height="315" src="http://www.youtube.com/embed/<?php .$rand_key.?>" frameborder="0" allowfullscreen></iframe></h1>
<h2><iframe id="vid2" width="560" height="315" src="http://www.youtube.com/embed/<?php .$rand_key.?>" frameborder="0" allowfullscreen></iframe><h2>
</p>
</html>
我似乎无法弄清楚如何从一组视频中随机选择一个视频并将其放在网站上。你能帮帮我吗?
答案 0 :(得分:2)
正如DevZer0所评论的那样,array_rand()返回一个数组键,而不是它的值。在您的示例中,您需要
$rand_key = isset($_GET['id']) ? $_GET['id'] : $video[$rand];
答案 1 :(得分:1)
你试过..
$rand_key = isset($_GET['id']) ? $_GET['id'] : $rand[0];