Array
(
[0] => Job
[1] =>
[2] => Array
(
[0] => stdClass Object
(
[AppDataId] => 16368
[JobTitle] => Sigma Six Black Belt/Lean Administration Consultant
[Abstract] => Sigma Six Black Belt/Lean Administration Consultan ... - open
)
[1] => stdClass Object
(
[AppDataId] => 16367
[JobTitle] => General Manager (Power Generation)
[Abstract] => General Manager (Power Generation) - Botswana
)
[2] => stdClass Object
(
[AppDataId] => 16366
[JobTitle] => Resident Engineer - Mpumalanga
[Abstract] => Resident Engineer - Mpumalanga - Mpumalanga
)
)
[3] =>
)
I need to get this into a PHP array and list all the JobTitle's or any other field
I've done this but I cannot figure out how to access only JobTitle firstly, and then secondly list all of them. $json_url is the actual url of the json file that outputs the info above.
$json1 = file_get_contents($json_url);
$array = json_decode($json1);
echo "<pre>";
print_r($array);
echo "</pre>";
$strJob=array();
foreach ($array as $value) {
$strJob[2][1]=$value->JobTitle;
}
echo '<br/>';
print_r($strJob);
echo '<br/>';
$strJob[2][1]=$value->JobTitle;- now how is that supposed to make any sense? The only entry you are creating in your array$strJobis the one under the keys [2][1], and you are overwriting that one in every loop iteration.$array[2]to begin with, because only that contains the sub-structure of objects to loop over. And then you simply add the job title as a new entry into your array,$strJob[]=$value->JobTitle;