My json data is like this :
$json_data = '{"2": "1", "3": "3"}';
Note :
2 = star, 1 = user, 3 = star, 3 = user
If I have variables like this :
$user = 3;
$star = 4;
I want check variable $user
exist in $json_data
or not
If exist, it will update to be :
$json_data = '{"2": "1", "4": "3"}';
So, if $user
exist in $json_data
, it will update $star
I try like this :
<?php
$user = 3;
$star = 4;
$json_data = '{"2": "1", "3": "3"}';
$array_data = json_decode($json_data, true);
if(in_array($user, $array_data))
{
// update here
}
?>
I'm still confused, how to update it
Is there anyone who can help me?