Home  >  Article  >  Backend Development  >  Analyze the usage of functions serialize() and unserialize()

Analyze the usage of functions serialize() and unserialize()

巴扎黑
巴扎黑Original
2017-08-11 13:29:511515browse

This article mainly introduces the relevant information of php's serialize() function and unserialize() function. Friends who need it can refer to

php's serialize() function and unserialize() function.

Applicable scenarios: serialize() returns a string. This string contains a byte stream representing value and can be stored anywhere. This facilitates storing or passing PHP values ​​without losing their type and structure. The more useful place is when storing data in a database or recording it in a file

serialize() can handle all types except resource types, and can also serialize objects


<?php 
$array = array(); 
$array[&#39;keys&#39;] = &#39;www&#39;; 
$array[&#39;values&#39;]=&#39;11111&#39;; 
$a = serialize($array); 
echo $a; 
unset($array); 
$a = unserialize($a); 
print_r($a); 
?>

Output


a:2:{s:4:"keys";s:3:"www";s:6:"values";s:5:"11111";}

Array ( [keys] => www [values] => 11111 )

The same applies to classes

The above is the detailed content of Analyze the usage of functions serialize() and unserialize(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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