I'm using CakePHP to create a products database system. In CakePHP, I have an array of all products in the 'products' table. Each product (an element in the 'products' array) has a function 'toArray()'. This converts the product into an associative array. How could I take an array of all the products and add the 'toArray()' of each product to a new array. This is my current flow:
$products = [$product1, $product2, $product3];
$newArr = [];
foreach($products as $product) {
$newArr[] = $product->toArray();
}
Is there a one-liner for something like this?