Example 1 — Serializing Simple Values
See what the serialized form looks like for an integer, a string, a boolean, null and a float.
<?php
echo serialize(42), PHP_EOL;
echo serialize('hello'), PHP_EOL;
echo serialize(true), PHP_EOL;
echo serialize(null), PHP_EOL;
echo serialize(1.5), PHP_EOL; How It Works
- Integers start with i. i:42; means an integer with the value 42.
- Strings include their length. s:5:"hello"; says a string of 5 characters follows.
- Booleans use b and null uses N. true becomes b:1; and null becomes N;.
- Floats start with d. d:1.5; stands for a double, which is PHP's float type.

