PHP unserialize() Function
PHP unserialize() Function
The unserialize() function in PHP takes a single serialized variable and converts it back into a PHP value.
Syntax
unserialize ( string $str [, array $options ] )
Parameter
value(required)- This parameter represents the serialized string.
options(optional)- This parameter signifies any options to be provided to unserialize().
Return
This function returns the converted value. The value can be a boolean, array, float, integer or string.
Example 1
Output
After the serialize() function...
a:3:{i:0;s:4:"Java";i:1;s:3:"PHP";i:2;s:6:"Python";}
After the unserialize() function...
array(3) {
[0]=>
string(4) "Java"
[1]=>
string(3) "PHP"
[2]=>
string(6) "Python"
}
Example 2
Output
a:2:{i:4;s:5:"April";i:5;s:3:"May";}
After the unserialize() function...
array(2) {
[4]=>
string(5) "April"
[5]=>
string(3) "May"
}
Example 3
Output
Serialized Array...
a:4:{s:1:"a";s:2:"Hi";s:1:"b";s:3:"Hey";s:1:"c";s:5:"Hello";s:1:"d";s:7:"Namaste";}
Unserialized Array...
a%3A4%3A%7Bs%3A1%3A%22a%22%3Bs%3A2%3A%22Hi%22%3Bs%3A1%3A%22b%22%3Bs%3A3%3A%22Hey%22%3Bs%3A1%3A%22c%22%3Bs%3A5%3A%22Hello%22%3Bs%3A1%3A%22d%22%3Bs%3A7%3A%22Namaste%22%3B%7D
