title: PHP: manipulate array making value as key recursively
body: <p>I got this array:</p>
  
  <pre><code>array:2 [▼
    0 =&gt; array:1 [▼
      0 =&gt; array:7 [▼
       "id" =&gt; "1"
       "producer" =&gt; "Samsung"
       "model" =&gt; "LE22B541C4W"
       "category" =&gt; "1"
       "production_date" =&gt; "2009-05-08"
       "status" =&gt; "Discontinued"
       "type" =&gt; "LCD"
       ]
    ]
    1 =&gt; array:1 [▼
      0 =&gt; array:7 [▼
       "id" =&gt; "2"
       "producer" =&gt; "Samsung"
       "model" =&gt; "P24FHD"
       "category" =&gt; "1"
       "production_date" =&gt; "0000-00-00"
       "status" =&gt; "Discontinued"
       "type" =&gt; "LCD"
      ]
    ]
   [...]
  ]
  </code></pre>
  
  <p>I would like to take the "ID" value of each array and make as primary key and remove the useless keys like this</p>
  
  <pre><code>array:2 [
    1 =&gt; array:7 [
      "id" =&gt; "1"
      "producer" =&gt; "Samsung"
      "model" =&gt; "LE22B541C4W"
      "category" =&gt; "1"
      "production_date" =&gt; "2009-05-08"
      "status" =&gt; "Discontinued"
      "type" =&gt; "LCD"
      ]
    2 =&gt; array:7 [
     [...]
  </code></pre>
  
  <p>By now I'm just populate the array using this simple query and a for loop:</p>
  
  <pre><code>foreach ($compatibility as $compElement) {
  
          $sql = "SELECT * FROM product WHERE ID = '$compElement';";
  
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $stmt = $em-&gt;getConnection()-&gt;prepare($sql);
          $stmt-&gt;execute();
          $thisElement = $stmt-&gt;fetchAll();
  
          $compArray[] = $thisElement;
  
      }
  </code></pre>