Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP数组输出仅显示一个元素_Php_Arrays_Video_Youtube - Fatal编程技术网

PHP数组输出仅显示一个元素

PHP数组输出仅显示一个元素,php,arrays,video,youtube,Php,Arrays,Video,Youtube,我正在开发一个小的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 = Ar

我正在开发一个小的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> 
尝试使用此代码-

<?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>

我的看法

<?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>


为什么要将数组传递给URL?我已经编辑了代码,使其更清晰。它看起来像是你实际使用的代码的精确表示吗?@VishnuBhadoriya他不是。目标是为用户提供一个播放列表问题现在已被编辑,但他在url中传递数组而不使用implode@VishnuBhadoriya即使在编辑之前,他也没有向URL传递数组。代码很难阅读,但并非不可能;除非您引用的编辑未进入修订历史记录。