2016-08-24 115 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>