- is_numeric: documentation ( source)
- trim: documentation ( source)
- json_encode: documentation ( source)
- array_walk_recursive: documentation ( source)
- range: documentation ( source)
- gzdeflate: documentation ( source)
<?php
$array=array("number"=>"3","string"=>"abc","null"=>null);
$ncache=array();
$scache=array();
foreach(range(1,10000) as $it)
{
$ncache[]=$array;
$scache[]=$array;
}
function ncompress(&$v)
{
if(is_numeric($v)) $v=floatval($v);
elseif(is_string($v)) $v=trim($v);
elseif(is_null($v)) $v=null;
}
function scompress(&$v)
{
if(is_numeric($v)) $v=floatval($v);
elseif(is_string($v)) $v=trim($v);
elseif(is_null($v)) $v="";
}
array_walk_recursive($ncache,"ncompress");
array_walk_recursive($scache,"scompress");
echo "Length of null : ".strlen(json_encode($ncache).'('.strlen(gzdeflate(json_encode($ncache))).')');
echo "\n";
echo "Length of string: ".strlen(json_encode($scache).'('.strlen(gzdeflate(json_encode($scache))).')');