Php 用变量回显数组号
我已经从json文件创建了一个数组,可以很好地调用缩略图/标题Php 用变量回显数组号,php,arrays,vimeo,Php,Arrays,Vimeo,我已经从json文件创建了一个数组,可以很好地调用缩略图/标题 <?php $file_contents = file_get_contents("http://vimeo.com/api/v2/username/videos.json"); $data = json_decode($file_contents); $image= $data[0]->{'thumbnail_large'}; $title= $data[1]->{'title'};
<?php
$file_contents = file_get_contents("http://vimeo.com/api/v2/username/videos.json");
$data = json_decode($file_contents);
$image= $data[0]->{'thumbnail_large'};
$title= $data[1]->{'title'};
?>
<?php
echo '<img src="'.$image.'"/>';
echo $title;
?>
但是,我想用$image回显数组号,这样我就不必为每个缩略图或标题创建多个变量,例如$image1$image2等
下面是上面代码的一个版本,我用$num来解释我的意思
<?php
$file_contents = file_get_contents("http://vimeo.com/api/v2/olouali/videos.json");
$data = json_decode($file_contents);
$image[$num]= $data[$num]->{'thumbnail_large'};
?>
<?php
echo '<img src="'.$image[$num].'"/>';
?>
我不确定这是否是我试图创建的内容的正确方法,因为我仍在学习php 试试这个:
<?php
$file_contents = file_get_contents("http://vimeo.com/api/v2/olouali/videos.json");
$data = json_decode($file_contents);
$count = count($data);
for($i = 0; $i < $count; $i++) {
echo '<img src="'.$data[$i]->{'thumbnail_large'}.'"/>';
}
感谢您的反馈。一旦我添加了这个新代码,哪个变量控制数组数$计数,$data??