user3268379
user3268379

Reputation: 141

Php Array accessing

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

Answers (4)

Debflav
Debflav

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

mathius1
mathius1

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

esqew
esqew

Reputation: 44693

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

Upvotes: 0

John Conde
John Conde

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

Related Questions