分析错误:语法错误,意外';[';,预期';)';,可能是PHP版本问题


Parse error: syntax error, unexpected '[', expecting ')', possibly PHP version issue

我的代码给出了一个错误。我现在知道这与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;

感谢

错误是将$post['tags']传递给函数声明。您可以更改

$func = function($post['tags'])
...

$func = function($tags) {
    $i=0; 
    while(!empty($tags)){ 
        return $tags[$i]." ";
        $i++;
    }
}

并称之为

$func($post['tags'])