the html
<input type="hidden" name="test[]" id="test" value= "" />
the js
jQuery(document).on('click', '#target', function () {
var jsArr = ["val1", "val2", "val3"];
jQuery('input[name^="test[]"]').val(JSON.stringify(jsArr));
});
the php
$json = $_POST['test'];
var_dump($json);
//array(1) { [0]=> string(43) "[\"val1\",\"val2\",\"val3\"]" }
var_dump($json[0]);
//string(43) "[\"val1\",\"val2\",\"val3\"]"
var_dump(json_decode($json[0]));
//return NULL
my json string is a valid json format so I don't know why that does not work. Any idea?
echo json_last_error_msg();and let's see what PHP doesn't like.