0

This is how I create the array

var list = $("#sortable").sortable('toArray');

$.ajax({
       type: 'POST',
       url: " some path ",
       data: { "list" : JSON.stringify(list) },
       success: function(data) {}
});

In DB it looks like that

["34","37","38","40","41","42","43","44","45","48","49","50"]

No I want to use this as array in php. How can I convert this string to an array? I tried with unserialize() method but this does not seem the way to go.

1
  • 1
    PHP's unserialize is only for strings serialized with PHP's serialize, you are actually sending JSON, so, json_decode. Commented Jun 27, 2012 at 7:39

2 Answers 2

3

You could use the json_decode function:

$arr = json_decode($_POST["list"])
Sign up to request clarification or add additional context in comments.

Comments

1

Do not stringify the json object, let jQuery handle that for you.

$.ajax({
       type: 'POST',
       url: " some path ",
       data: { "list" : list }, // here, it's not necessary to stringify the json object.
       success: function(data) {}
});

Then you get the array in php by $_POST['list'].

Comments

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.