Reputation: 141
I am trying to access an item from the array, the issue is with the line:
src=$videoArray[0]
I have tried a few ways but none seem to work.
<?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>
Upvotes: 0
Views: 51
Reputation: 1151
Maybe need reusable code...
<?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
}
?>
Upvotes: 0
Reputation: 1391
You need <?php ?>
tags for the array to echo out, and you are missing the quotes around the src attribute.
<iframe width="520" height="280" src="<?php echo $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>
Upvotes: 3
Reputation: 44693
<iframe width="520" height="280" src="<?php $videoArray[0] ?>" frameborder="0" allowfullscreen></iframe>
Upvotes: 0
Reputation: 219834
You forgot your PHP tags and echo statement:
<iframe width="520" height="280" src="<?php echo $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>
or shorthand syntax:
<iframe width="520" height="280" src="<?= $videoArray[0]; ?>" frameborder="0" allowfullscreen></iframe>
Upvotes: 1