note 46788 deleted from function.serialize by aharvey
| From: | aharvey@php.net | Date: | Tue, 06 Nov 2012 02:05:53 +0000 |
| Subject: | note 46788 deleted from function.serialize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191752@lists.php.net to get a copy of this message | ||
Note Submitter: areddan at silverarm dot ie
----
<?php
/*
This is an array_walk style serialize that works with multi dimensional arrays, it also base64
encodes and decodes to allow ';' to exist in the array.
-- Alan Reddan
*/
$data[qwerty] = "blah";
$data[1][a] = "1aa";
$data[2][b] = "2bb";
$data[3][c] = ";;;;;;";
//To Serialise Call :
array_walk($data,'base64_encoder_multi');
$serialized_string = serialize($data);
//print $serialized_string . '\n'; //uncomment to see serialized array
//To Unserialize Call
$array = unserialize($serialized_string);
array_walk($array,'base64_cleaner_multi');
print_r($array);
//start functions
function base64_encoder_multi(&$val,$key) {
if (is_array($val)) array_walk($val,'base64_encoder_multi',$new);
else {
$val = base64_encode($val);
}
}
function base64_cleaner_multi(&$val,$key) {
if (is_array($val)) array_walk($val,'base64_cleaner_multi',$new);
else {
$val = base64_decode($val);
}
}
//ends
?>