Php question: Print variable names
We are developing a website in php where 2 pictures are displayed. Each time you refresh the page the pictures shuffle. The pictures are stored in an array:
$pictures = array ( '49ers.jpg', 'bears.jpg', 'bengals.jpg',
'bills.jpg', 'broncos.jpg',
'browns.jpg', 'buccaneers.jpg',
'cardinals.jpg', 'chargers.jpg', 'cheifs.jpg', 'colts.jpg', 'cowboys.jpg', 'dolphins.jpg', 'eagles.jpg', 'falcons.jpg', 'giants.jpg', 'jaguars.jpg', 'jets.jpg', 'lions.jpg',
'packers开发者_StackOverflow.jpg', 'panthers.jpg', 'patriots.jpg', 'raiders.jpg', 'rams.jpg', 'ravens.jpg', 'redskins.jpg', 'saints.jpg', 'seahawks.jpg', 'steelers.jpg', 'texans', 'titans.jpg', 'vikings.jpg', );
How would we write an echo/print statement to display the file names of the pictures below?
var_dump($pictures);
or
print $pictures[0] // returns 49ers.jpg
print_r($pictures);
If you are able to show to image on the page. Can't you just print the filename that you use in your html.. Assuming it's something like: <img src="images/<%= $url %>" />
-> <p><img src="images/<%= $url" /></p><p><%= $url %></p>
?
<?php
$pictures = array('49ers.jpg', 'bears.jpg', 'bengals.jpg',
'bills.jpg', 'broncos.jpg',
'browns.jpg', 'buccaneers.jpg',
'cardinals.jpg', 'chargers.jpg', 'cheifs.jpg', 'colts.jpg', 'cowboys.jpg', 'dolphins.jpg', 'eagles.jpg', 'falcons.jpg', 'giants.jpg', 'jaguars.jpg', 'jets.jpg', 'lions.jpg',
'packers.jpg', 'panthers.jpg', 'patriots.jpg', 'raiders.jpg', 'rams.jpg', 'ravens.jpg', 'redskins.jpg', 'saints.jpg', 'seahawks.jpg', 'steelers.jpg', 'texans', 'titans.jpg', 'vikings.jpg');
//foreach ($pictures as $value) {
echo '<pre>';
print_r($pictures);
//exit;
?>
精彩评论