Javascript Muilti Sub Array
<p>i have a javascript code which generates dynamic sub arrays.</p>

<pre><code>function createArray() {

    var myArr = new Object();
    myArr[0] = createSubArray('apple');
    myArr[1] = createSubArray('Mango');
    myArr[2] = createSubArray('Pineapple');
    myArr[3] = createSubArray('Grape');
    document.getElementById("a").innerHTML = JSON.stringify(myArr);
    return myArr;

}


function createSubArray(name){
    var arr = new Object();
    elems = document.getElementsByName(name);
    for (var i=0;i&lt;elems.length;i++){
        if (elems[i].checked){
            arr[name] =  elems[i].value;
            arr['price'] =  elems[i].getAttribute('data-price');
        }
    }
    return arr;

}
</code></pre>

<p>And i got the output as below</p>

<pre><code>array
  0 =&gt; 
    array
      'apple' =&gt; string 'light' (length=5)
      'price' =&gt; string '10' (length=2)
  1 =&gt; 
    array
      'apple' =&gt; string 'light1' (length=5)
      'price' =&gt; string '10' (length=2)
  2 =&gt; 
    array
      'Mango' =&gt; string 'dark' (length=4)
      'price' =&gt; string '40' (length=2)
  3 =&gt; 
    array
      'Pineapple' =&gt; string 'dark' (length=4)
      'price' =&gt; string '60' (length=2)
  4 =&gt; 
    array
      'Grape' =&gt; string 'dark' (length=4)
      'price' =&gt; string '80' (length=2)
</code></pre>

<p>But i need to array to be like below</p>

<pre><code>array
  0 =&gt; 
    array
      'apple' =&gt; string 'light' (length=5)
       0 =&gt; 
           array
            'apple' =&gt; string 'light' (length=5)
            'price' =&gt; string '10' (length=2)
       1 =&gt; 
           array
            'apple' =&gt; string 'light1' (length=5)
            'price' =&gt; string '10' (length=2)
  1 =&gt; 
    array
      'Mango' =&gt; string 'light' (length=5)
       0 =&gt; 
           array
            'Mango' =&gt; string 'light' (length=5)
            'price' =&gt; string '10' (length=2)
  2 =&gt; 
    array
      'Pineapple' =&gt; string 'light' (length=5)
       0 =&gt; 
           array
            'Pineapple' =&gt; string 'light' (length=5)
            'price' =&gt; string '10' (length=2)
</code></pre>

<p>so i have changed the javascript like this </p>

<pre><code>function createArray()
{
    var myArr = new Object();
    var _tempa = new Array();
    var elems = document.getElementsByTagName("input");
     for (var i=0;i&lt;elems.length;i++)
     {  if (elems[i].checked){
         _tempa.push(elems[i].getAttribute('name'));
            myArr[i] = createSubArray1(_tempa);
          }
      }
     document.getElementById("a").innerHTML = JSON.stringify(myArr);
    return myArr;
} 

function createSubArray1(namearr){

    var arr1 = new Object();
    for (var j=0;i&lt;namearr.length;j++){
    var elems = document.getElementsByName(name[j]);
    for (var i=0;i&lt;elems.length;i++){
        if (elems[i].checked)
        {
        arr1[elems[i].getAttribute('data-gpname')] =  createSubArray(elems[i].getAttribute('name'));
        }
    }
    }
    return arr1;
}

 function createSubArray(name){
    var arr = new Object();
    var elems = document.getElementsByName(name);
    for (var i=0;i&lt;elems.length;i++){
        if (elems[i].checked)
        {
        arr['productname'] =  elems[i].value;
        arr['price'] =  elems[i].getAttribute('data-price');
        }
    }
    return arr;
}
</code></pre>

<p>After this i am getting the out put like below</p>

<pre><code>[{},{}]
</code></pre>

<p>My Html Is Below</p>

<pre><code>&lt;form method="post"&gt;
Apple
&lt;input type="radio" onclick="createArray()" id="one" name="apple" data-gpname="apple" data-price="10" value="light"/&gt; Light
&lt;input type="radio" onclick="createArray()" id="two" name="apple" data-gpname="apple" data-price="20" value="dark" /&gt; Dark
&lt;input type="radio" onclick="createArray()" id="one1" name="apple1" data-gpname="apple"  data-price="120" value="light2"/&gt; Light11
&lt;input type="radio" onclick="createArray()" id="two1" name="apple1" data-gpname="apple" data-price="210" value="dark1" /&gt; Dark22
&lt;input type="text" id="appleqty" name="appleqty" value="" /&gt;
&lt;br&gt;
Mango
&lt;input type="radio" onclick="createArray()" id="three" name="Mango" data-gpname="Mango"  data-price="30" value="light"/&gt; Light
&lt;input type="radio" onclick="createArray()" id="one" name="Mango" data-gpname="Mango" data-price="40" value="dark" /&gt; Dark
&lt;input type="text" id="Mangoqty" name="Mangoqty" value="" /&gt;
&lt;br&gt;
Pine Apple
&lt;input type="radio" onclick="createArray()" id="four" name="Pineapple" data-gpname="Pineapple" data-price="50" value="light"/&gt; Light
&lt;input type="radio" onclick="createArray()" id="five" name="Pineapple" data-gpname="Pineapple" data-price="60" value="dark" /&gt; Dark
&lt;input type="text" id="Pineappleqty" name="Pineappleqty" value="" /&gt;
&lt;br&gt;
Grape
&lt;input type="radio" onclick="createArray()" id="six" name="Grape" data-gpname="Grape" data-price="70" value="light"/&gt; Light
&lt;input type="radio" onclick="createArray()" id="seven" name="Grape" data-gpname="Grape" data-price="80" value="dark" /&gt; Dark
&lt;input type="text" id="Pineappleqty" name="Pineappleqty" value="" /&gt;

&lt;textarea name="a" id="a" cols="50"&gt;&lt;/textarea&gt;
&lt;input type="submit" name="se" value="se" /&gt;
&lt;/form&gt;
</code></pre>

<p>I have used <code>php json_decode</code> to get the array Structure </p>
