Array to String PHP? Array to String PHP? arrays arrays

Array to String PHP?


You can use json_encode()

<?php$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);echo json_encode($arr);?>

Later just use json_decode() to decode the string from your DB.Anything else is useless, JSON keeps the array relationship intact for later usage!


json_encode($data) //converts an array to JSON stringjson_decode($jsonString) //converts json string to php array

WHY JSON : You can use it with most of the programming languages, string created by serialize() function of php is readable in PHP only, and you will not like to store such things in your databases specially if database is shared among applications written in different programming languages