Home > Backend Development > PHP Tutorial > Detailed explanation of serialize() and unserialize() function examples in php

Detailed explanation of serialize() and unserialize() function examples in php

小云云
Release: 2023-03-20 06:34:02
Original
1537 people have browsed it

php’s serialize() function and unserialize() function

Applicable situations: serialize() returns a string, which contains a byte stream representing value and can be stored anywhere. This facilitates storing or passing PHP values ​​without losing their type and structure. A more useful place is when data is stored in a database or recorded in a file. This article mainly introduces you to the relevant information of PHP's serialize() function and unserialize() function. Friends who need it can refer to it. I hope it can help everyone.

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); 
?>
Copy after login

Output


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

Array ( [keys] => www [values] => 11111 )
Copy after login

The same applies to classes.

Related recommendations:

Detailed examples of serialize() serialization function in jquery

Analysis of functions serialize() and unserialize() Usage

Example of using serialize() method to submit form data in jQuery ajax

The above is the detailed content of Detailed explanation of serialize() and unserialize() function examples in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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