我的代码出错了。我知道现在它与php版本有关。但是我应该更改我的代码以使其正常工作?
$json = file_get_contents(
'https://api.instagram.com/v1/users/'. $user_id .'/media/recent/?client_id=' . $client_id . '&count=' . $count);
$decode = json_decode($json, true);
$output = '';
$func = function($post['tags']){
$i=0;
while(!empty($post['tags'])){
return $post['tags'][$i]." ";
$i++;
}
};
foreach ($decode['data'] as $post) {
$output .= $modx->getChunk($tpl,
array(
'link' => $post['link']
,'image' => $post['images']['standard_resolution']['url']
,'likes' => $post['likes']['count']
,'hashtags' => $func
)
);
}
return $output;
由于
答案 0 :(得分:0)
错误是您将$post['tags']
传递给函数声明。你可以改变
$func = function($post['tags'])
...
到
$func = function($tags) {
$i=0;
while(!empty($tags)){
return $tags[$i]." ";
$i++;
}
}
并将其称为
$func($post['tags'])