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_value
s (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?