How to convert laravel collection to php array

In this blog we will discuss how to convert laravel collection to simple php array.


Laravel collection to array

Laravel use toArray() function on collection for changing simple array.

public function index() {
    $arr = [1,3,5,7,9];
    $collection = collect($arr); //change array to collection
    dd($collection->toArray()); //change again collection to array.
}

Laravel collection to json

Laravel use toJson() function on collection for changing json type data.

public function index() {
    $arr = [1,3,5,7,9];
    $collection = collect($arr); //change array to collection
    dd($collection->toJson()); //change collection to json object.
}
php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links