1. execution speed serialize() vs json_encode()
serialize() is slower than json_encode() as compare to execution, serialize() take more time to execute than json_encode
so score is json_encode() :: 1 and serialize() :: 0
2. memory usage
serialize() is use more execution memory as compare to json_encode()
so score is json_encode() :: 2 and serialize() :: 0
3. ease of use
$student=array(array("name"=>"sam","roll_no"=>10,"semester"=>3),
array("name"=>"jaddy","roll_no"=>11,"semester"=>3) ,
array("name"=>"garg","roll_no"=>12,"semester"=>3)
);
echo $data= serialize($student)."<br/>";
echo $data= json_encode($student);
serialize() return
a:3:{i:0;a:3:{s:4:"name";s:3:"sam";s:7:"roll_no";i:10;s:8:"semester";i:3;}i:1;a:3:{s:4:"name";s:5:"jaddy";s:7:"roll_no";i:11;s:8:"semester";i:3;}i:2;a:3:{s:4:"name";s:4:"garg";s:7:"roll_no";i:12;s:8:"semester";i:3;}}
json_encode() return
[{"name":"sam","roll_no":10,"semester":3},{"name":"jaddy","roll_no":11,"semester":3},{"name":"garg","roll_no":12,"semester":3}]
json_encode() returned value simply awesome and human friendly . so it is very easy to debug , analyze , compare and to use.
in ease of use json_encode() win again over serialize()
so score is json_encode() :: 3 and serialize() :: 0
4. storage wise performance
json_encode() returned string take less space to store in database / session / files as compare to serialize() ,
echo $data= strlen(serialize($student)) ; // 216
echo $data= strlen(json_encode($student)); // 127
its almost double space occupied by serialize() returned string
so score is json_encode() :: 4 and serialize() :: 0
so it is clean win of json_encode() over serialize() , one can use json_encode() without doubt over serialize()