I'm not sure if I'm even asking the question correctly, but here goes.
I have a JSON file that looks more or less like this:
[{
"programName": "Entrepreneurial Skills",
"description": "The Certificate in Entrepreneurial Skills 1 provides you, as a small business owner/operator, with the essential skills and competitive strategies to help your enterprise thrive.",
"faculty": "School of Business and Economics",
"department": "Marketing, International Business and Entrepreneurship",
"id": 79,
"parentId": 0,
"relatedIds": [3, 4, 5, 16, 26, 27],
"tabGroup": 0,
"credentialType": "Certificate",
"credentialName": "Certificate in Entrepreneurial Skills",
"programCode": "",
"programOption": "",
"delivery": "distance",
"campus": "",
"length": { "credits": 15, "courses": 0, "weeks": 0, "months": 0, "years": 0, "varies": false },
"intakeDates": "",
"internationalFriendly": false,
"careers": "",
"priorityResult": false,
"url": "distance/programs/business-management/certificate-in-entrepreneurial-skills-1",
"imageUrl": "",
"tags": ""
}, {
"programName": "Environmental Economics and Management",
"description": "Attain a broad knowledge of the business environment, advanced management skills and specialized knowledge in environmental economics and sustainability.",
"faculty": "School of Business and Economics",
"department": "Economics",
"id": 80,
"parentId": 0,
"relatedIds": [45,67,88],
"tabGroup": 4,
"credentialType": "Master",
"credentialName": "Master in Environmental Economics and Management",
"programCode": "MEEM",
"programOption": "",
"delivery": "campus",
"campus": "",
"length": { "credits": 0, "courses": 0, "weeks": 0, "months": 0, "years": 2, "varies": false },
"intakeDates": "",
"internationalFriendly": true,
"careers": ["Economic sustainable management"],
"priorityResult": true,
"url": "programs/catalogue/masters-degrees-environmental-economics-and-management",
"imageUrl": "meem-msceem-banner39755.jpg",
"tags": ""
},{ etc }]
I am putting that file into an array like so:
$programData = json_decode($json, true);
and then subsequently stepping through it and storing it in a $content variable that will be displayed in HTML. It more or less looks like this (simplified):
foreach ($programData as $key => $value) {
$content.='<h4 class="credentialName">'.$value['credentialName'].'</h4>';
$content.='<p class="lead">'.$value['description'].'</p>';
etc...
}
Within that foreach, I reach a point where I have another foreach going through the relatedProgram items. These are integers that are meant to match up - and display - the URL/title of the related ID in the JSON array. These IDs do not match the key of the item in the JSON array. This is where I'm having a problem. How do I find the key of the $programData
-> $id
3 (for example), then get the $url
and $programName
from that item, from within the foreach
?
I've googled and overflowed to the nth degree and I'm stumped. Any help would be very appreciated!