I'm doing something stupid and can't figure it out.
I'm pulling setting details stored in a mysql database as a json object and then converting them to an array.
$settings = (array)json_decode($user['settings']);
I can print_r() this to the following:
Array
(
[2] => 1
[1] => 1
)
Good so far.
If I try to update one of the settings, so for example changing 1 to equal 0, I get this:
Array
(
[2] => 1
[1] => 1
[1] => 0
)
I'm doing this simply with this:
$settings[1] = 0;
Ultimately I'm trying to unset the value if it's a 0 and then update the database. Instead of updating the value, it's creating a new entry and using unset doesn't do anything.
What am I doing wrong??
full code snippet for reference:
$settings = (array)json_decode($user['settings']);
print_r($settings);
if(isset($form['usr'][$user['id_user']])){
$settings[1] = 1;
}else{
$settings[1] = 0;
unset($settings[1]);
}
print_r($settings);
returns:
Array
(
[2] => 1
[1] => 1
)
Array
(
[2] => 1
[1] => 1
[1] => 0
)