WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to do an import of an array of checkboxes, but there is a value that I don't how it is determined.

The array is based on a user meta option that I created that shows a list of category checkbox options. It grabs all of the categories and creates a checkbox option that can be saved to a user's profile.

This is part of the coding I used to create the user meta option:

$args = array( 'hide_empty' => 0, 'taxonomy'=> 'category');
$categories =  get_categories($args);

if ($categories){
                        foreach ( $categories as $category ){ 
                            if(in_array($category->term_id,(array)$data)) {
                                $selected = 'checked="checked""';
                            } else {
                                $selected = '';
                            echo '<input name="user_cats[]" value="'.$category->term_id.'" '.$selected.' type="checkbox"/> '.$category->name.'<br/>';

This is what the options look like in the user profile page:

enter image description here

After doing a test save of the some of the checkbox selections, I examined the database value of the "user_cats" field, it gives me something like this:


Now, I know what all but one of the variables stand for.

a = Total amount (quantity) of selections

i = Sequential number of the selection (*Starting with 0)

"X" = The number value within the parenthesis is the category ID

My question is, what is the s: value based on? I tried comparing to

share|improve this question
var_dump(unserialize('a:2:{i:0;s:2:"20";i:1;s:3:"343";}')); – EarnestoDev Oct 21 '11 at 23:13
S stands for string – Bainternet Oct 21 '11 at 23:16
unserialize() the string to get the array. ru.php.net/manual/en/function.serialize.php – soulseekah Oct 22 '11 at 5:58
up vote 2 down vote accepted

Use the php function unserialize() on that string and you will get a proper array.

$cats = get_cats_from_database();
$cats = unserialize($cats);
        //now $cats is an array like Array(0 => 20, 1 => 343 );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.