Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP how can i append data into a serialized array

If I have a serialized array... how can I append more values to it? Should I unserialize it first -> add data and then serialize it again?

like image 417
kmunky Avatar asked Nov 01 '09 22:11

kmunky


1 Answers

Yes.

function addItem($serializedArray, $item)
{
   $a = unserialize($serializedArray);
   $a[] = $item;
   return serialize($a);
}
like image 164
Ewan Todd Avatar answered Oct 04 '22 00:10

Ewan Todd