SUGGESTED DUPLICATE ANSWER DOES NOT SOLVE
I have 4 hidden inputs where the value increments based on user actions. Var Id gets the id of each input value and var val its value.
<input class="howmanyproducts" id="<?php echo $value; ?>" name="<?php echo $value; ?>" type="hidden" value="0">
I push each set of values into an array which will output:
8(id), 1(val)
9, 2
3, 5
7, 8
I need to sort these values based on the val. So the above should return:
7, 8
3, 5
9, 2
8, 1
Below is what I have so far, hope the question makes sense!
$("#proddiv .howmanyproducts").each(function() {
var id = this.id;
var val = $(this).val();
ids.push([id, +val]);
});
ids.sort(function(b, a) { return a[1] - b[1]; });
$("#productorder").val(ids);
$("#productscore").submit();
Below is how I retrieve the form data which needs to be in sorted
$prodorder = $_POST['productorder'];
$array2 = array_unique(explode(',', $prodorder));
My current code is not changing the order at all!