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:
//example of array before decoding it [{"id":1,"quantity":12, other values...},{"id":2,"quantity":13,other values...}]
$data = json_decode($request->data);
$newArray = array();
foreach ($data as $key => $value){
$newArray[$key] = $value->{'id'} //[1,2,3....]
}
at the moment I am generating a one-dimensional array, what I need is to obtain an array of this type:
[
1 => ['quantity' => $other],
2 => ['quantity' => $other]
]
where 'other' would be another value that I get from my loop $value->{'other'}
. How can I generate this?