I am working with JSON data and trying to check if a hovered element matches the names 'sports' or 'technology'. If there is a match, I want to retrieve the corresponding 'text' and 'image' values. However, I am only able to retrieve the indexes and not the actual names like 'sports' or 'technology' for comparison.
I am unsure if my JSON array is structured correctly for this task, but I am open to making adjustments as needed.
Any suggestions on how to approach this?
[
{
"sports":{
"image":"",
"text":"\u003Cp\u003EWe believe businesses that are people-focused and have a well-defined story are poised for success. That\u2019s why we bring together branding and ownable experience design for our clients. Lorem ipsum dolor sit amet, consectetuer adipiscing.\u003C\/p\u003E"
}
},
{
"media---entertainment":{
"image":"",
"text":""
}
},
{
"lifestyle":{
"image":"",
"text":""
}
},
{
"technology":{
"image":"",
"text":""
}
},
{
"education":{
"image":"",
"text":""
}
}
]
Would restructuring the JSON array like this be more effective?
[
{
"sports":{
"image":"",
"text":"\u003Cp\u003EWe believe businesses that are people-focused and have a well-defined story are poised for success. That\u2019s why we bring together branding and ownable experience design for our clients. Lorem ipsum dolor sit amet, consectetuer adipiscing.\u003C\/p\u003E"
},
"media---entertainment":{
"image":"",
"text":""
},
"lifestyle":{
"image":"",
"text":""
},
"technology":{
"image":"",
"text":""
},
"education":{
"image":"",
"text":""
}
}
]
The PHP code used to generate the JSON looks like this:
$clientsSectorsArray = array();
foreach ($sectors as $sector) {
$clientsSectorsArray[] = array(
"{$sanitizer->pageName($sector->global_text)}" => array(
"image" => "{$sector->global_image->url}",
"text" => "{$sector->global_textarea}",
)
);
}
$clientsSectors = json_encode($clientsSectorsArray);