title: How to get data in Array category wise?
body: <p>I have below data coming from loop:  </p>
  
  <pre><code>$array = Array(
  [0]=&gt;Array(
      [0]=&gt;Cat 1
      [1]=&gt; Q1
      [2]=&gt; A1
      )
  [1]=&gt;Array(
      [0]=&gt;Cat 1
      [1]=&gt; Q2
      [2]=&gt; A2
      )
  [2]=&gt;Array(
      [0]=&gt;Cat 2
      [1]=&gt; Q1
      [2]=&gt; A1
      )
  [3]=&gt;Array(
      [0]=&gt;Cat 3
      [1]=&gt;Sub Cat 3
      [2]=&gt;Q1
      [3]=&gt;A1
      )
  [4]=&gt;Array(
      [0]=&gt;Cat 3
      [1]=&gt;Sub Cat 3
      [2]=&gt;Q2
      [3]=&gt;A2
      )       
  )
  )
  </code></pre>
  
  <p>I need data in Array like</p>
  
  <pre><code>$array_res = Array(
  ['Cat 1']=&gt;Array(
      [0]=&gt;Array(
          [0]=&gt; Q1
          [1]=&gt; A1
          )
      [1]=&gt;Array(
          [0]=&gt; Q2
          [1]=&gt; A2
          )
      )
  ['Cat 2']=&gt;Array(
      [0]=&gt;Array(
          [0]=&gt; Q1
          [1]=&gt; A1
          )
      )
  ['Cat 3']=&gt;Array(
      ['Sub Cat 3']=&gt;Array(
          [0]=&gt;Array(
              [0]=&gt; Q1
              [1]=&gt; A1
          )
          [1]=&gt;Array(
              [0]=&gt; Q2
              [1]=&gt; A2
          )
          )
      )
  
  )
  </code></pre>
  
  <p>It should return data in Array/Associative Array. So can fetch data loop wise &amp; print it. I want the arrays created dynamically when there are array values inside an array like sub cat 3.</p>