I have a array of array data which is came from database. And my "array to xml converter" can convert only one level array.
Basicly I want to convert my database table to xml file.
public function downloadXml()
{
$fields = ['created_at', 'updated_at'];
$products = Product::where('user_id', auth()->id())
->exclude($fields)->get()->toArray();// this is returnin array of array like [0 => [], 1 => []]
$products = array_collapse($products);
$result = ArrayToXml::convert($product, 'product');
}
The problem is array_collapse method trim the one level array but give me only last array not all arrays. How can I get all arrays? Any help appreciated..
Edit: when dd(Product::where('user_id', auth()->id())
->exclude($fields)->get()->toArray();
);
Output1 = array:2 [▼ 0 => array:18 [▶] 1 => array:18 [▶] ]
When dd(array_collapse(Product::where('user_id', auth()->id())
->exclude($fields)->get()->toArray());
)
Output2 = array:18 [▶]
I need something like output2 but the problem is output2 assuming there is only one product but actualy there is two product.