1

I want to save a long array in mysql database and when i read that array back from mysql database, i want that array back in proper array format. Is this possible?

Other threads are suggesting to convert array into string using serialise and explode. But will they help me to get proper array back? Thanks.

2
  • What format has your array? Simple key values? Commented May 9, 2013 at 8:41
  • a normal array, array('something'=>'value',.....) Commented May 9, 2013 at 8:43

2 Answers 2

3

You can try it yourself.

As an alternative to serailize(), you can use json_encode().

sidenote: reverse of serialize() is unserialize(), not explode().

sidenote: reverse of json_encode() is json_decode().

sidenote: Very worthwhile to read: Discussion of json_encode() vs serialize()

Sign up to request clarification or add additional context in comments.

Comments

0

Usually, serialize and unserialize functions are used for such purposes.

With serialize you can convert your array to a string and than get an array by applying unserialize on string you get from serialize.

And about explode: you may use it too, but than you will need to use implode function to serialize array. But it will work with simplest one dimensional arrays only:

implode(",", array("val1", "val2", "val3")) = "val1,val2,val3"

1 Comment

agree that implode() can be helpful for very simple array, but it does not handle array elements that contents ,, which will produce unwanted results. Still, serialize() & json_encode() are preferred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.