duanqiao0153 2015-11-17 15:53
浏览 20
已采纳

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

My code is giving an error. I know now it has to do with the php version. 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

  • 写回答

1条回答 默认 最新

  • doufang6268 2015-11-17 15:58
    关注

    The error is that you pass $post['tags'] to the function declaration. 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'])
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致