-1

I have an array that look like :

Array ( [0] => Array ( [names] => somename [rating] => 10 ) [1...]=>...)

And I am saving him in the database by converting him to a string by this way :

$array_string=mysql_escape_string(serialize($list));

And then I'm pushing him into the database.

Then, I'm taking this array (string in the database) into my page, and I'm doing unserialize this way :

$list= unserialize($query_row['list']);

And then I convert this string into array this way :

$arr=explode("|", $list);

Now I have a problem, when I'm checking by var_dump($arr); its printing me :

array(1) { [0]=> string(422) "Array( [0] => Array ( [names] => e [rating] => 5 ) [1] => Array ( [names] => d [rating] => 4 ) [2] => Array ( [names] => c [rating] => 3 ) [3] => Array ( [names] => b [rating] => 2 ) [4] => Array ( [names] => a [rating] => 1 ))" }

I don't know how to convert the string inside the array (string(422)) into array. Anyone have an idea? Thanks.

  • 2
    As suggested in the comments to your [other question](http://stackoverflow.com/questions/26449973/convert-array-to-string-and-get-it-back-to-array-in-php), please provide a [Short, Self Contained, Correct Example](http://sscce.org/) to your problem. Nobody understands what you're talking about. – georg Oct 19 '14 at 16:34

1 Answers1

0

If your goal is to return the data as an array after you unserialize it then you don't have to explode, just by unserializing it is returned to its original state as an array.
Quoting the PHP Documentation: The converted value is returned, and can be a boolean, integer, float, string, array or object.

So simply,

$list = unserialize($serialized_array); 

$list would be an array in this case that you can use just like it was before serializing.

Ali
  • 3,479
  • 4
  • 16
  • 31
  • Not sure who downvoted my answer but I edited it again, it was my bad as I mixed between unserialize and json_decode. – Ali Oct 19 '14 at 16:38
  • It's not me downvoted, you are right - but this isn't what I asked. Look at the bold highlight in my post. – David Alexandrovich Oct 19 '14 at 16:54