w3resource

PHP: unserialize() function

Description

The unserialize() converts to actual data from serialized data.

Version:

(PHP 4 and above)

Syntax:

unserialize(string1)

Parameter:

Name Description Required /
Optional
Type
string1 The serialized string. Required String

Return value:

Converted value. The value can be a boolean, array, float, integer or string.

Value Type: Mixed*.

*Mixed : Mixed indicates that the return value may multiple (but not necessarily all) types.

Example:

<?php
$serialized_data = serialize(array('Math', 'Language', 'Science'));
echo  $serialized_data . '<br>';
// Unserialize the data
$var1 = unserialize($serialized_data);
// Show the unserialized data;
var_dump ($var1);
?>

Output :

a:3:{i:0;s:4:"Math";i:1;s:8:"Language";i:2;s:7:"Science";}
array(3) {    [0]=>    string(4) "Math"    [1]=>    string(8) "Language"    [2]=>    string(7) "Science"  } 

View the example in the browser

Practice here online :

See also

PHP Function Reference

Previous: strval
Next: unset



PHP: Tips of the Day

How do I get PHP errors to display?

Example:

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

However, this doesn't make PHP to show parse errors - the only way to show those errors is to modify your php.ini with this line:

display_errors = on

(if you don't have access to php.ini, then putting this line in .htaccess might work too):

php_flag display_errors 1

Ref : https://bit.ly/2NqCEmr