Home > Backend Development > PHP Tutorial > Applying PHP Serialization Array Techniques_PHP Tutorial

Applying PHP Serialization Array Techniques_PHP Tutorial

WBOY
Release: 2016-07-15 13:34:07
Original
1219 people have browsed it

serialize --------- Format the array into an ordered string
unserialize ----- Restore the array into Array

PHP serialized array test example:

$test = array("a"=>0,"b"=> ;0,"c"=>0);
$test2 = '';
$test2=serialize($test);
echo $test2;
echo "


" ;
print_r(unserialize($test2));

PHP serialization array usage:

In my personal experience, it mainly deals with array transfer and array storage operate.

For example, I have an array that needs to be passed to the next page. If you don’t want to use seesion/cookie, then you can use this function, pass it, and then restore it.
For example, when I was making a website directory, there was a rating, which was divided into positive, medium and negative ratings. Then my database has only one field designed for this function, and the type is long character. Combine three comments into an array:

array(
'a' => 0, //0 positive reviews
'b' => 0, //0 neutral reviews
'c' => 0 //0 negative comments
)

After converting it with the serialize function, it is: a:3:{s:1:"a";i:0 ;s:1:"b";i:0;s:1:"c";i:0;}, then the database exists. Don't forget to use the unserialize function to convert it into an array when taking it out.

The above is the correct way to use PHP serialized arrays.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446013.htmlTechArticleserialize --------- Format the array into an ordered string unserialize ---- - Restore the array to an array PHP serialized array test example: $test = array(a=0,b=0,c=0); $test2 = ''; $t...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template