Convert Collection to Array in Few Lines

Submitted by kmlnyk - 8 months ago

Its Diffucult to convert whole object to an array . Normally we are Doing it By Iterate through foreach. By using Below Code we will reduce amount of line of code

<?php
/* 
  $data Would be the Collection object which we want to convert
*/
$result = array_map(function($object){
                        return (array) $object;
                       }, $data);
                       
                       
                       ?>

Ads cover the costs of maintaining Laravel-tricks

comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks