I have been looking or a way to change an objects key name with no success as of yet. I need to be able to parse ALL through the keys in the resulting set, check the name of the key, and assign it a new key name (NOT VALUE) if the name of the key matches a variable $name. I will include my code below:
$infocusArray = array();
if($result = $conn->query($query))
// Start
while($row = mysqli_fetch_assoc($result)) {
array_push($infocusArray, $row);
};
foreach($row as $key => $element){
echo $key; => outputs key names
};
file_put_contents('data.json', json_encode($infocusArray));
echo count($infocusArray);
}
data.json result of json_encode($infocusArray):
[
{
"id": "ai-101010",
"sector": "guidance",
"date": "10-11-2030"
},
{
"id": "ai-191011",
"sector": "airfield",
"date": "03-01-2023"
}
]
The dataset I am working with is much larger however I am removing most items for simplicity sake.