[wp-hackers] Removing empty values from serialized array

Dan Gayle dangayle at gmail.com
Thu Aug 5 17:44:47 UTC 2010

I have an options setting page that uses the register_setting() and
settings_fields() functions to store my data in a serialized array,
following the example set by Ozh here:

When this field is unchecked, the key/value pair in the ozh_sample
array is completely removed:
<input name="pms_options[option1]" type="checkbox" value="1" <?php if
(isset($options['option1'])) checked('1', $options['option1']); ?> />

When this field is left blank, however, the value is blank, but the key remains:
<input type="text" name="pms_options[affiliateID]" value="<?php echo
(isset($options['affiliateID']) ) ? $options['affiliateID'] : NULL ;

So my question is twofold: why does the checkbox go away completely,
and how can I get an empty options array key to go away? I've tried
unsetting it, setting it to NULL, everything I can think of. How can
you get rid of an empty value from a serialized array?

More information about the wp-hackers mailing list