-2

As I'm not an advanced PHP programmer, my rudimentary knowledge on PHP says, PHP arrays are like below:

$indexed_array = array( 1, 'Toothless', 23, 2456 );
$associative_array = array( 1 => 'Toothless', 2 => 2456 );
$multidimensional_array = array( 'me' => 'Toothless', 'nature' => 'Fearless' );

And right now I came to know about the PHP shorthand array() property:

$shorthand_array = [ 1, 'Toothless', 23, 2456 ];
$shorthand_mixture = [ 'me' => 'Toothless', 1, 'nature' => 'Fearless' ]; *

* source^

I'm actually a fan of WordPress and in WordPress postmeta table, WP stores some meta_values (type:longtext) in a text like this (no space, a pure block of string):

a:3:{i:571;s:16:"path/to/image.ext";i:572;s:16:"path/to/image.ext";i:411;s:16:"path/to/image.ext";}

using jsfiddle's TidyUp I understood that, it's an array:

a: 3: {
    i: 571;
    s: 16: "path/to/image.ext";
    i: 572;
    s: 16: "path/to/image.ext";
    i: 411;
    s: 16: "path/to/image.ext";
}

I can decipher this now that, a stands for array, value 3 means it has 3 indexes; i denotes index and it stored the ID of the attachment, and s denotes string (char. count besides every s) and it stored the path of the attachment. ...Using CMB2 plugin I found the same storage structure.

Now I'm working on a Raw PHP project where database structure and storage planning is on my own. So I'm thinking of something like this in repeating fields. I want to store common repeating fields under a same meta_key, and will retrieve the individual field and its associative value using an array like this.

BTW, I can't understand how can I store data in this format from PHP, what types of array is this? And how actually I can generate a complex string (actually an array) like this from user input?

Mayeenul Islam
  • 4,532
  • 5
  • 49
  • 102
  • 6
    This is not array, its serialized version of array . you can universalize it and get the array version . – Amir Habibzadeh Feb 15 '15 at 10:25
  • possible duplicate of [unserialize() \[function.unserialize\]: Error at offset](http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset) – Rizier123 Feb 15 '15 at 10:30

1 Answers1

3

See the PHP functions serialize() and unserialize():

serialize()

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

unserialize()

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

Rounin
  • 27,134
  • 9
  • 83
  • 108