Skip to content
Advertisement

PHP ForEach Array – display variables

I have a Curl query which outputs JSON as $response

JavaScript

I have turned this into the below Array:

JavaScript

How can I loop through this array, to show each job on a website. I need to turn some of the fields into variables, for example, jobTitle

I have tried the below but nothing is output back;

JavaScript

Advertisement

Answer

According to your array structure, the following code snippet should do the trick. You decode your JSON payload as an associative array by adding the second argument of true to the json_decode function, so it shouldn’t being accessed as an object.

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