I want to update my JSON object according to user input using PHP , my JSON file looks like this :
[
{
id=1,
text= "Sam",
},
{
id=2,
text= "Jack",
}
]
I want to update the text with what the user will input
I want to update my JSON object according to user input using PHP , my JSON file looks like this :
[
{
id=1,
text= "Sam",
},
{
id=2,
text= "Jack",
}
]
I want to update the text with what the user will input
Kindly check your json format because it is not valid. This is my code, hope this will help you.
//your input
$id = 1;
$input = "john";
//decode your json
$info = json_decode($json);
foreach ($info as $data) {
if ($data->id == $id) { //find the id
$data->text = $input; //update json object text depends on the user input
}
}
then you can return the info to display update
return $info;