Robinvm
2 years ago

Make a foreach with a JSON array

Posted 2 years ago by Robinvm

Hello, i want to make a foreach with info from JSON, but i cant get it to work.

This is the JSON {"extractorData":{"url":"http://www.gametracker.com/search/minecraft/?","resourceId":"ef620045b25dd59aaf787ed293b77a72","data":[{"group":[{"ip":[{"text":"188.212.101.184"}],"port":[{"text":":25565"}]},{"ip":[{"text":"37.187.143.232"}],"port":[{"text":":25565"}]},{"ip":[{"text":"37.187.155.150"}],"port":[{"text":":25565"}]},{"ip":[{"text":"149.202.88.8"}],"port":[{"text":":25565"}]},{"ip":[{"text":"178.33.168.228"}],"port":[{"text":":25565"}]},{"ip":[{"text":"151.80.111.140"}],"port":[{"text":":25565"}]},{"ip":[{"text":"37.221.210.41"}],"port":[{"text":":25565"}]},{"ip":[{"text":"136.243.174.135"}],"port":[{"text":":25565"}]},{"ip":[{"text":"91.121.101.49"}],"port":[{"text":":25565"}]},{"ip":[{"text":"92.222.126.77"}],"port":[{"text":":25565"}]},{"ip":[{"text":"149.56.28.188"}],"port":[{"text":":25565"}]},{"ip":[{"text":"188.212.102.151"}],"port":[{"text":":30002"}]},{"ip":[{"text":"158.69.23.185"}],"port":[{"text":":25565"}]},{"ip":[{"text":"149.202.65.52"}],"port":[{"text":":25565"}]},{"ip":[{"text":"37.143.163.10"}],"port":[{"text":":25565"}]}]}]},"pageData":{"resourceId":"ef620045b25dd59aaf787ed293b77a72","statusCode":200,"timestamp":1487618249143},"url":"http://www.gametracker.com/search/minecraft/?","runtimeConfigId":"ac291588-acfe-4d3a-9b48-1f770166ca96","timestamp":1487618249718,"sequenceNumber":-1}

And this is what i got now:

$area = json_decode($string, true);

        foreach($area['port'] as $i => $v)
        {
            echo $v['port'].'<br/>';
        }

Could someone help me to get this to work?

Please sign in or create an account to participate in this conversation.