PHP function serialize ():
This function is to serialize the data and return a stored string that facilitates storing or passing PHP values without losing its type and structure. So we often see this structure in the CMS database.
In general, we will be complex or the amount of data is not necessary to separate the storage of data encapsulated into a multidimensional array through serialize () into a string, and then into the database, when needed to be taken out to the number of groups again, and took out the number of units used is PHP unserialize (), One more UN in front. Directly on the example:
$a =array ("Week", "full", "and", "Personal", "blog", "Www.php.net", "duet", "Personal blog"), $b =serialize ($a);p rint_r ($b); echo "
"; $c =unserialize ($b);p rint_r ($c);
The output is:
Data obtained after serialize serialization is also stored in the database a:8:{i:0;s:3: "Week"; I:1;s:3: "Full"; I:2;s:3: "and"; I:3;s:6: "Personal"; I:4;s:6: "blog"; i:5;s:20: " Www.php.net "; I:6;s:9:" Duet and "; I:7;s:12:" Personal blog ";} The data obtained by Unserialize () deserialization is the same as the previous $ A array structure ([0] = = Week [1] = [2] = = AND [3] = [4] = + Blog [5] = WW w.php.net [6] = duet and [7]/= Personal blog)
In the previous example of a more complex two-dimensional array:
$a 1=array ( ' name ' =>array ("Week", "full", ' and '), ' Name_weburl ' =>array ("Duet and", "www.php.net"), ' all ' = Array (' Duet and personal blog ' = ' www.php.net ')), $b 1=serialize ($a 1);p Rint_r ($b 1); echo "
"; $c 1=unserialize ($b 1); Print_r ($c 1);
The output is:
The data obtained after serialize serialization is also stored in the database a:3:{s:4: "Name"; A:3:{i:0;s:3: "Week"; I:1;s:3: "Full"; I:2;s:3: "and";} s:11: "Name_weburl"; A:2:{i:0;s:9: "Duet and"; I:1;s:20: "Www.php.net";} S:3: "All"; a:1:{s:21: "Duet and personal Blog"; s:20: "Www.php.net";}} The data obtained by Unserialize () deserialization is the same as the previous $ A array structure ([name] = = Array ([0] = = Week [1] = full [2] = =) [Name_weburl] = > Array ([0] = duet and [1] = www.php.net) [All] = Array ([Duet and personal blog] = www.php.net))