title: Insert values into an associative array within a loop
body: <p>I am new working with php, I am using a foreach loop to traverse an array of decoded objects. I would like to enter values to a new array for each iteration. This is a part of the code:</p>
  
  <pre><code>//example of array before decoding it [{"id":1,"quantity":12, other values...},{"id":2,"quantity":13,other values...}]
  $data = json_decode($request-&gt;data); 
  $newArray = array();
  
  foreach ($data as $key =&gt; $value){
    $newArray[$key] = $value-&gt;{'id'} //[1,2,3....]
  }
  </code></pre>
  
  <p>at the moment I am generating a one-dimensional array, what I need is to obtain an array of this type: </p>
  
  <pre><code>[
      1 =&gt; ['quantity' =&gt; $other], 
      2 =&gt; ['quantity' =&gt; $other]
  ]
  </code></pre>
  
  <p>where 'other' would be another value that I get from my loop <code>$value-&gt;{'other'}</code>. How can I generate this?</p>