Cheatsheet: PHP

Cheatsheet: PHP

February 12, 2021


Convert a storable representation of a value. The serialize() function converts a storable representation of a value. To serialize data means to convert a value to a sequence of bits so that it can be stored in a file, a memory buffer, or transmitted across a network.

$colors = array("Red", "Green", "Blue");
$serialized_colors = serialize($colors);
echo $serialized_colors;

//OUTPUT: a:3:{i:0;s:3:"Red";i:1;s:5:"Green";i:2;s:4:"Blue";}


Convert serialized data back into actual data:

$serialized_colors = 'a:3:{i:0;s:3:"Red";i:1;s:5:"Green";i:2;s:4:"Blue";}';
$unserialized_colors = unserialize($serialized_colors);

//OUTPUT: Array ( [0] => Red [1] => Green [2] => Blue )


Encodes data with MIME base64

$str = 'Coding is fun...';
echo base64_encode($str);

//OUTPUT: Q29kaW5nIGlzIGZ1bi4uLg==



The json_decode() function is used to decode or convert a JSON object to a PHP object.

$result = json_decode($jsondata, true); // Return arrry
$result = json_decode($jsondata); // Return object



The json_encode() function is used to encode a value to JSON format.


The date() function formats a local date and time, and returns the formatted date string. The date function should have at least one parameter.

date(format, timestamp)



Leave A Comment