0

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

Whirl Mind
  • 884
  • 1
  • 9
  • 18
Tessed
  • 57
  • 1
  • 7

1 Answers1

0

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'])
user2655603
  • 410
  • 3
  • 11