php - json object to array not referencing values -
i'm doing stupid , can't figure out.
i'm pulling setting details stored in mysql database json object , converting them array.
$settings = (array)json_decode($user['settings']);
i can print_r() following:
array ( [2] => 1 [1] => 1 ) good far.
if try update 1 of settings, example changing 1 equal 0, this:
array ( [2] => 1 [1] => 1 [1] => 0 ) i'm doing this:
$settings[1] = 0;
ultimately i'm trying unset value if it's 0 , update database. instead of updating value, it's creating new entry , using unset doesn't anything.
what doing wrong??
full code snippet 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 )
hi can add secent param true function json_decode :
$settings = json_decode($user['settings'], true); i think fix problem
Comments
Post a Comment