Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.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 - Fatal编程技术网

Php数组访问

Php数组访问,php,Php,我正在尝试从阵列访问项目,问题在于行: src=$videoArray[0] 我试过几种方法,但似乎都不管用 <?php $videoArray = array( "//www.youtube.com/embed/nEBHkEeH42Y", "//www.youtube.com/embed/1GlticqrECU", "//www.youtube.com/embed/BMOUsI8JIaI", ); ?> <iframe width="520" height="280"

我正在尝试从阵列访问项目,问题在于行:

src=$videoArray[0]
我试过几种方法,但似乎都不管用

<?php
$videoArray = array(
"//www.youtube.com/embed/nEBHkEeH42Y",
"//www.youtube.com/embed/1GlticqrECU",
"//www.youtube.com/embed/BMOUsI8JIaI",
);
?>



<iframe width="520" height="280" src=$videoArray[0] frameborder="0" allowfullscreen></iframe>

您忘记了PHP标记和echo语句:

<iframe width="520" height="280" src="<?php echo $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>

您忘记了PHP标记和echo语句:

<iframe width="520" height="280" src="<?php echo $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>
您需要
标记才能对数组进行回显,并且缺少src属性周围的引号

<iframe width="520" height="280" src="<?php echo $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>
您需要
标记才能使数组回显,并且缺少src属性周围的引号

<iframe width="520" height="280" src="<?php echo $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>

可能需要可重用的代码

<?php
$videoArray = array(
    "//www.youtube.com/embed/nEBHkEeH42Y",
    "//www.youtube.com/embed/1GlticqrECU",
    "//www.youtube.com/embed/BMOUsI8JIaI",
);

foreach($videoArray as $videoLink) {
    ?>
    <iframe width="520" height="280" src="<?php echo $videoLink; ?>" frameborder="0" allowfullscreen></iframe>
    <?php
}
?>


可能需要可重用的代码

<?php
$videoArray = array(
    "//www.youtube.com/embed/nEBHkEeH42Y",
    "//www.youtube.com/embed/1GlticqrECU",
    "//www.youtube.com/embed/BMOUsI8JIaI",
);

foreach($videoArray as $videoLink) {
    ?>
    <iframe width="520" height="280" src="<?php echo $videoLink; ?>" frameborder="0" allowfullscreen></iframe>
    <?php
}
?>


make it src=”“您不能像那样从HTML访问PHP变量。make it src=”“您不能像那样从HTML访问PHP变量。不要使用shorttags@keaner正确的评论是,“如果你打算发布你的软件并支持5.4之前的php版本,就不要使用短标记”。不,John,永远不要使用短标记。未来的证据:)思维已经过时。用于回显的短标记(
“PHP还允许使用短打开标记(不鼓励使用短打开标记),因为它们仅在使用Short_open_tag PHP.ini配置文件指令启用时可用,或者如果PHP配置了--enable Short tags选项。”我同意echo部分,但一般来说,你不应该使用短标签tags@keaner正确的评论是,“如果你打算发布你的软件并支持5.4之前的php版本,就不要使用短标记”。不,John,永远不要使用短标记。未来的证据:)这种想法已经过时。短标记用于回音(
“PHP还允许使用短开放标记(不鼓励使用短开放标记,因为它们仅在使用short_open_tag PHP.ini配置文件指令启用时可用,或者如果PHP配置了--enable short tags选项。”我同意echo部分,但一般情况下不应使用短标记。