Skip to content
Advertisement

PHP – Grab info from array

Im trying to get sensor value from my weather station. The API i get is in the array.

I can’t figure out how to only grab “temp” data from [“id”]=> “1549112871”. If I echo $sensor[“temp”] I will get temp data from whole array.

JavaScript

JavaScript

Advertisement

Answer

As your provided data, your data is a 2-dimensions array. Each array will have the keys: “id”, “temp”,… And you want to get the “temp” value of the array that has a specific “id”.

If you want to do so, you must loop through the array to find which array matched the desired “id”:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement