What type of structure is this data?

I have this mysql table with a field with this value:

a:18:{
i:0;
a:7:{
        i:0;
        i:10;
        i:1;
        s:5:"Email";
        i:2;
        s:10:"user_email";
        i:3;
        s:4:"text";
        i:4;
        s:1:"y";
        i:5;
        s:1:"y";
        i:6;
        s:1:"y";
    }
i:1;
a:7:{
        i:0;
        i:1;
        i:1;
        s:10:"First Name";
        i:2;
        s:10:"first_name";
        i:3;
        s:4:"text";
        i:4;
        s:1:"y";
        i:5;
        s:1:"y";
        i:6;
        s:1:"y";
    }
i:2;
a:7:{
        i:0;
        i:2;
        i:1;
        s:9:"Last Name";
        i:2;
        s:9:"last_name";
        i:3;
        s:4:"text";
        i:4;
        s:1:"y";
        i:5;
        s:1:"y";
        i:6;
        s:1:"y";
    }
i:3;
a:7:{
        i:0;
        i:4;
        i:1;
        s:9:"Address 2";
        i:2;
        s:5:"addr2";
        i:3;
        s:4:"text";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:4;
a:7:{
        i:0;
        i:5;
        i:1;
        s:4:"City";
        i:2;
        s:4:"city";
        i:3;
        s:4:"text";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:5;
a:7:{
        i:0;
        i:6;
        i:1;
        s:5:"State";
        i:2;
        s:8:"thestate";
        i:3;
        s:4:"text";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:6;
a:7:{
        i:0;
        i:7;
        i:1;
        s:3:"Zip";
        i:2;
        s:3:"zip";
        i:3;
        s:4:"text";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:7;
a:7:{
        i:0;
        i:9;
        i:1;
        s:9:"Day Phone";
        i:2;
        s:6:"phone1";
        i:3;
        s:4:"text";
        i:4;
        s:1:"y";
        i:5;
        s:1:"y";
        i:6;
        s:1:"n";
    }
i:8;
a:7:{
        i:0;
        i:9;
        i:1;
        s:9:"Alt Phone";
        i:2;
        s:6:"phone2";
        i:3;
        s:4:"text";
        i:4;
        s:1:"y";
        i:5;
        s:1:"y";
        i:6;
        s:1:"n";
    }
i:9;
a:9:{
        i:0;
        i:9;
        i:1;
        s:9:"GENDER";
        i:2;
        s:6:"gender";
        i:3;
        s:4:"select";
        i:4;
        s:1:"y";
        i:5;
        s:1:"y";
        i:6;
        s:1:"n";
        i:7;
        s:4:"male";
        i:8;
        s:5:"female";
    }
i:10;
a:7:{
        i:0;
        i:11;
        i:1;
        s:13:"Confirm Email";
        i:2;
        s:13:"confirm_email";
        i:3;
        s:4:"text";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:11;
a:7:{
        i:0;
        i:3;
        i:1;
        s:9:"Address 1";
        i:2;
        s:5:"addr1";
        i:3;
        s:4:"text";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:12;
a:7:{
        i:0;
        i:8;
        i:1;
        s:7:"Country";
        i:2;
        s:7:"country";
        i:3;
        s:4:"text";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:13;
a:7:{
        i:0;
        i:14;
        i:1;
        s:8:"Password";
        i:2;
        s:8:"password";
        i:3;
        s:8:"password";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:14;
a:7:{
        i:0;
        i:15;
        i:1;
        s:16:"Confirm Password";
        i:2;
        s:16:"confirm_password";
        i:3;
        s:8:"password";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
    }
i:15;
a:9:{
        i:0;
        i:16;
        i:1;
        s:3:"TOS";
        i:2;
        s:3:"tos";
        i:3;
        s:8:"checkbox";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"n";
        i:7;
        s:5:"agree";
        i:8;
        s:1:"n";
    }
i:16;
a:7:{
        i:0;
        i:12;
        i:1;
        s:7:"Website";
        i:2;
        s:8:"user_url";
        i:3;
        s:4:"text";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"y";
    }
i:17;
a:7:{
        i:0;
        i:13;
        i:1;
        s:17:"Biographical Info";
        i:2;
        s:11:"description";
        i:3;
        s:8:"textarea";
        i:4;
        s:1:"n";
        i:5;
        s:1:"n";
        i:6;
        s:1:"y";
    }
}

I’ve seen this multiple times before in other databases, but I’m not sure what type of data type/field this is? Reason I ask because I’m trying to get make element in there for input type “select” but can’t seem to figure it out. Anyone know?

Read More

From my understanding, the above data is serialization of form input elements, like text box, check box, etc.

So how would they serialize a select input box? For example:

<select>
  <option value='1'>1</option>
  <option value='2'>2</option>
</select>

Related posts

Leave a Reply

1 comment

  1. It’s serialized data, most likely by the php function serialize()

    http://php.net/manual/en/function.serialize.php

    Description:

    string serialize ( mixed $value ) Generates a storable representation
    of a value.

    This is useful for storing or passing PHP values around without losing
    their type and structure.

    To make the serialized string into a PHP value again, use
    unserialize().

    Example:

    <?php
      $obj = new stdclass;
      $obj->prop1 = 1;
      $obj->prop2 = "two";
      $arr = array(0, 1, 2, array("key" => "value", "another key" => "another value"), $obj);
      print serialize($arr);
    ?>
    

    will output:
    a:5:{i:0;i:0;i:1;i:1;i:2;i:2;i:3;a:2:{s:3:"key";s:5:"value";s:11:"another key";s:13:"another value";}i:4;O:8:"stdClass":2:{s:5:"prop1";i:1;s:5:"prop2";s:3:"two";}}

    And to explain a snippet of yours, take:

    a:18:{
    i:0;
    a:7:{
            i:0;
            i:10;
            i:1;
            s:5:"Email";
            i:2;
            s:10:"user_email";
            i:3;
            s:4:"text";
            i:4;
            s:1:"y";
            i:5;
            s:1:"y";
            i:6;
            s:1:"y";
        }
    

    It’s saying the data is an array with 18 elements a:18, the element at index 0 i:0 is an array of 7 elements a:7, the element at index 0 of that array i:0 is an integer with the value 10 i:10, the element at index 1 i:1 is a string of length 5 s:5 with the value email. and so on.

    a var_dump of just the first element from your serialized data gives:

    array(1) {
      [0]=>
      array(7) {
        [0]=>
        int(10)
        [1]=>
        string(5) "Email"
        [2]=>
        string(10) "user_email"
        [3]=>
        string(4) "text"
        [4]=>
        string(1) "y"
        [5]=>
        string(1) "y"
        [6]=>
        string(1) "y"
      }
    }
    

    To serialize your particular snippet – well, there’s a few ways to do it and i don’t have a wordpress handy to verify it, but one way would simply be to represent it in php like this:

    $input = array('type' => 'select');
    $opts = array(array('value' => 1, 'text' => '1'), array('value' => 2, 'text' => '2'));
    $input['options'] = $opts;
    $serialized = serialize($input);
    

    which would give you a string that looks like
    a:2:{s:4:"type";s:6:"select";s:7:"options";a:2:{i:0;a:2:{s:5:"value";i:1;s:4:"text";s:1:"1";}i:1;a:2:{s:5:"value";i:2;s:4:"text";s:1:"2";}}}