Your method is correct, but the problem is that the value inside the option in your example, i.e.:
get_option( 'second_option' );
is not serialized correctly ( it was either edited directly–and incorrectly–through the database or inserted with something other than update_option()
).
If you var_dump( get_option( 'second_option' ) );
, you’ll see that it’s not an array but a string.
The correct serialized value in the database for your example would be:
a:3:{s:6:”manual”;s:0:””;s:8:”currency”;s:3:”USD”;s:5:”state”;s:2:”nn”;}
Using that, your approach will work as expected. However, instead of editing this manually (as it is prone to errors, like in this example), just do a reset of the option like so:
$second_option = array(
'manual' => '',
'currency => 'USD',
'state' => 'nn',
);
update_option( 'second_option', $second_option );
Afterwards, this will work as expected:
$sets = get_option( 'second_option' );
$sets['currency'] = 'some_value';
update_option( 'second_option', $sets );
PS: There is no need to unserialize or serialize when using get_option() and update_option() respectively, these functions take care of that.