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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes.
function addItem($serializedArray, $item)
{
$a = unserialize($serializedArray);
$a[] = $item;
return serialize($a);
}
回答2:
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!
回答3:
yes, this is the only (reliable) way