Feeds tamper fetch data from external API
If I'm not mistaken {} indicates that it is an object and [] means that the variable is an array, therefor, I would expect $data-&gt;elements[0]-&gt;name would be the way to get the value in your return statement.

To improve your code, I would advise to use the empty() (or isset()) functions to check whether the elements in $data exists