开发者

PHP how can i append data into a serialized array

开发者 https://www.devze.com 2022-12-10 10:27 出处:网络
If I have a serialized array... how can I append more values to it? Sho开发者_如何学Pythonuld I unserialize it first -> add data and then serialize it again?Yes.

If I have a serialized array... how can I append more values to it? Sho开发者_如何学Pythonuld I unserialize it first -> add data and then serialize it again?


Yes.

function addItem($serializedArray, $item)
{
   $a = unserialize($serializedArray);
   $a[] = $item;
   return serialize($a);
}


Unserializing is the way to go, definitely. Unless you have a huge string, it'd be strongly recommended, unless you want to make your own strict interpreter.

Changing anything from a serialized array/object should be done very carefully - a single extra character would break everything if you don't update all previous numbers defining each piece of structure!


yes, this is the only (reliable) way

0

精彩评论

暂无评论...
验证码 换一张
取 消