Skip to content

Instantly share code, notes, and snippets.

@edomaru
Last active August 29, 2015 14:22
Show Gist options
  • Save edomaru/aeb602031cc7e7ff6d34 to your computer and use it in GitHub Desktop.
Save edomaru/aeb602031cc7e7ff6d34 to your computer and use it in GitHub Desktop.
Serialize-unserialize-issue
//to safely serialize
$safe_string_to_store = base64_encode(serialize($multidimensional_array));
//to unserialize...
$array_restored_from_db = unserialize(base64_decode($encoded_serialized_string));
// to update serialized data
$data = unserialize($serializedData);
if(array_key_exists('key', $data) {
$data['key'] = 'New Value';
}
$serializedData = serialize($data);
// I found this awesome code here:
// http://davidwalsh.name/php-serialize-unserialize-issues
// http://stackoverflow.com/questions/14446029/php-update-serialized-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment