Ankit Shah Ankit Shah - 1 year ago 49
PHP Question

How to get Serialize Output Data?

I need Output in this format:


I tried below code

$a = array('category_id',1);

echo serialize($a);


How to get above result? I also tried

Answer Source

Rewrite the array as

$a = array('category_id'=> "1 ");

As the serialised params are in the format type:length:value, you need to pass 1 as a string.

Also s:2:"1" won't be possible as 1 has a length of 1 not 2. If you wan't a string of 2 length, maybe we can pass <space> to acheive that.