【发布时间】:2016-12-31 22:08:14
【问题描述】:
我正在编写一个小型 PHP 脚本,该脚本将采用 youtube id 数组并动态生成 youtube 嵌入播放列表。
我正在使用的当前 PHP 代码 - 只回显一个视频。
<iframe width="560" height="315" src="http://www.youtube.com/embed/182oUgBfoLE?&rel=0&modestbranding=1&hd=1&autohide=1&playlist=
<?php
$videos = Array("PGNiXGX2nLU", "VUJOJ0d7e8c", "o0syTUu3_S0", "rXndd78C8-c" );
// Shuffle array
shuffle($videos);
// Loop array
foreach($videos as $video);
{
// Echo array with commas between elements
echo "$video ,";
}
?>
" frameborder="0" allowfullscreen></iframe>
我的问题是如何让洗牌和循环数组的所有元素得到回显?
【问题讨论】:
-
为什么要将数组传递给 url
-
我已经编辑了您的代码,使其更清晰。它看起来像您实际使用的代码的准确表示吗?
-
@VishnuBhadoriya 他不是。目标是为用户提供播放列表
-
问题现在已编辑,但他在 url 中传递数组而不使用 implode
-
@VishnuBhadoriya 即使在编辑之前,他也没有将数组传递给 URL。代码难以阅读,但并非不可能;除非您指的是没有进入修订历史的编辑。