2016-08-24 114 views
2

我正在研究一个小型PHP脚本,它将采用一组youtube id并生成一个即时嵌入式播放列表。PHP数组输出只显示一个元素

我正在使用的当前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> 

我的问题是我怎样才能得到混洗和循环数组的所有元素被回显?

+0

为什么你传递数组网址 –

+0

我已经编辑你的代码,以便它更易读。它看起来像是你实际使用的代码的准确表示吗? – MonkeyZeus

+0

@VishnuBhadoriya他不是。我们的目标是为用户提供一个播放列表 – MonkeyZeus

回答

1

我采取

<?php 

$videoIds = array("PGNiXGX2nLU", "VUJOJ0d7e8c", "o0syTUu3_S0", "rXndd78C8-c"); 
shuffle($videoIds); 
$playlist = implode(',', $videoIds); 

?> 
<iframe width="560" height="315" 
     src="http://www.youtube.com/embed/182oUgBfoLE?&rel=0&modestbranding=1&hd=1&autohide=1&playlist=<?= $playlist; ?>" 
     frameborder="0" allowfullscreen> 
</iframe> 
0

尝试使用此代码 -

<?php 
$videos = Array ("PGNiXGX2nLU", "VUJOJ0d7e8c", "o0syTUu3_S0", "rXndd78C8-c"); 
// Shuffle array 
shuffle($videos); 
$playlist = implode(',', $videos); 
?> 

<iframe width="560" height="315" src="http://www.youtube.com/embed/182oUgBfoLE?&rel=0&modestbranding=1&hd=1&autohide=1&playlist=<?php echo $playlist;?>" frameborder="0" allowfullscreen></iframe>