I have this PHP function:
function editDatas($datas, $got, $to_find, $to_replace) {
foreach($datas['datas'] as $key => $rows) {
foreach($rows as $number => $row) {
if($row['id'] == $got) {
$datas['datas'][$key][$number][$to_find] = $to_replace;
return $datas;
}
}
}
}
And this call:
$datas = json_decode(file_get_contents('datas.json'), true);
$datas = editDatas($datas, 'hotel_name', "value", 'My new hotel name');
My json is actually like this:
{
"datas": [
{
"category": "General",
"id": "hotel_name",
"type": "input",
"maxlength": "15",
"size": "10",
"label": "Hotel name",
"help": "Hotel name",
"value": "Rubi's hotel"
},
...
I'm trying to replace some value in my json.
The problem I'm facing is this error:
Illegal string offset 'id' in line 33
Which is the following in my function:
if($row['id'] == $got) {
I do not understand why because the id
is know.
Could you please help me to solve my problem.
Thanks.