Converting array to string and then back in PHP



PHP Snippet 1:

$string = serialize($array);

PHP Snippet 2:

$array = unserialize($string);

PHP Snippet 3:

$string = json_encode($array);
$array = json_decode($string);

PHP Snippet 4:

$array_as_string = implode(" ",$userarray);
$new_array = explode(" ",$array_as_string);

PHP Snippet 5:

$userarray = array('UserName' => $username, 'UserId' => $userId, 'UserPicURL' => $userPicURL);
$string = json_encode($userarray);
$backtoarray = json_decode($string);

PHP Snippet 6:

$userarray = array('UserName' => $username, 'UserId' => $userId, 'UserPicURL' => $userPicURL);
$string = serialize($userarray);
$backtoarray = unserialize($string);