I'm trying to fetch data coming from a request, I used PostMan to send the request. the following arrays are the output of dd($items); ... The data that I want from these arrays are the id and quantity
array:2 [ 0 => array:12 [ "id" => 4 "name" => "omnis" "image_name" => "https://source.unsplash.com/random" "description" => "Officiis ea provident eius perspiciatis provident et eveniet illo. Tempore ullam ab molestiae unde. Fugit pariatur consequatur sunt veritatis. Laudantium quos veritatis quasi dolorum." "price" => 9 "discount" => 0 "status" => 1 "category_id" => 24 "place_id" => 1 "created_at" => "2019-12-15 08:05:36" "updated_at" => "2019-12-15 08:05:36" "quantity" => 5 ] 1 => array:12 [ "id" => 5 "name" => "molestiae" "image_name" => "https://source.unsplash.com/random" "description" => "Debitis dignissimos est veritatis veritatis sit. Ut ex non nam aliquid dolore vero earum. Ab aliquid et quibusdam enim." "price" => 7 "discount" => 0 "status" => 1 "category_id" => 25 "place_id" => 1 "created_at" => "2019-12-15 08:05:36" "updated_at" => "2019-12-15 08:05:36" "quantity" => 3 ] ] I want to do foreach loop to get this:
{ "id":4, "quantity":5 }, { "id":5, "quantity":3 } It tried :
$item_array = []; foreach ($items as $key=>$item) { $item_array[$key] = $item['id']; $item_array[$key] = $item['quantity']; }