I want to prepare and save an multidimensional array to send it via ajax. I have this HTML for example:
<input type="checkbox" class="itArray" value="id,1,name,Alex,gender,male" />
<input type="checkbox" class="itArray" value="id,2,name,Max,gender,male" />
I want to achieve that every comma (,) seperates key:value pairs in a multidimensional array AND depending on the amount of commas it should create an array (e.g.: 5 commas = 3 key:value pairs like in this example).
The array from this HTML example should look like this then:
(Sorry if I'm putting wrong brackets, I just want to demonstrate what I want to achieve and I don't know the correct syntax)
That is what I have done so far:
var itemsArray;
$('.itArray').each(function(key, value) {
console.log(itemsArray);
val = $(value).val();
console.log("val " + val);
var ar = val.split(',');
var itemsArray = { // new each loop here with i % 2 ? }
// I don't know how to proceed here
}
});
I guess I have to use i % 2 to seperate each key:value pairs? But I don't know how to do that exactly in this specific case. I appreciate any help.
Edit: Added Image to show how I want it to look like. Sorry, had to hide sensible data.

{ "id": "1", "name": "Alex", "gender": "male" }, right?json_encodeon your data and see what you get.