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

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'])