a:3:{i:0;s:5:"apple";i:1;s:6:"banana";i:2;s:6:"orange";}Serialized object
O:8:"stdClass":2:{s:4:"name";s:4:"John";s:3:"age";i:30;}
serialize()
and unserialize()
?
serialize()
converts a PHP data structure (like an array or object) into a string that can be saved or transferred easily.
unserialize()
takes that storable/transferrable string and converts it back into the original PHP data structure.
Commonly, you might store serialized data in a file or database, or send it across a network (although JSON is often used these days for broader compatibility).
Note: Using unserialize()
on untrusted data can be dangerous because it may allow malicious code injection. Consider safer alternatives like JSON, or at least use strict options such as allowed_classes
to mitigate risks.