简体   繁体   English

解析错误:语法错误,意外的'[',期望')',可能是PHP版本问题

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

My code is giving an error. 我的代码给出了错误。 I know now it has to do with the php version. 我知道现在它与php版本有关。 But to what should i change my code for it to work correctly? 但是我应该更改我的代码以使其正常工作吗?

$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;

Thanks 谢谢

The error is that you pass $post['tags'] to the function declaration. 错误是您将$post['tags']传递给函数声明。 You can change 你可以改变

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

to

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

and than call it as 然后称其为

$func($post['tags'])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP 版本 4:: 解析错误:语法错误,意外 '=',期待 ')' - PHP version 4 :: Parse error: syntax error, unexpected '=', expecting ')' 解析错误:语法错误,意外的 '[',期待 ')' php - Parse error: syntax error, unexpected '[', expecting ')' php PHP解析错误:语法错误,意外的“:”,期待“;” 或者 '{' - PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' 解析错误:语法错误,意外的“|”,期望变量(T_VARIABLE)Symfony PHP VERSION WAMP Windows - Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) Symfony PHP VERSION WAMP Windows PHP版本5.2.14 /解析错误:语法错误,意外的T_FUNCTION,期望')' - PHP Version 5.2.14 / Parse error: syntax error, unexpected T_FUNCTION, expecting ')' Wordpress插件PHP解析错误:语法错误,意外的“ {”,预期为“)” - Wordpress plugin PHP Parse error: syntax error, unexpected '{', expecting ')' 解析错误:语法错误,意外的';',期望的是')'(Wordpress functions.php) - Parse error: syntax error, unexpected ';', expecting ')' (Wordpress functions.php) PHP解析错误:语法错误,意外的T_IS_EQUAL,预期 - PHP Parse error: syntax error, unexpected T_IS_EQUAL, expecting 的PHP-语法错误,意外的'(',期待')' - php - syntax error, unexpected '(', expecting ')' 解析错误:语法错误,意外'(',期待','或';'in - Parse error: syntax error, unexpected '(', expecting ',' or ';' in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM