Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mitismirza's avatar

laravel collect in php

hey guys. is there replace for laravel collect in php? i mean how can i do this in php and without laravel?


$persons  =  collect([
    'name'  => 'John' , 
    'family'  => 'jeferson',
    'age'     =>  26
]);

thanks.

0 likes
2 replies
Vilfago's avatar
Vilfago
Best Answer
Level 20

Collections are array, as superman is a man.

So you can do

$persons = array('name' => 'John', 'Family' => 'Jeferson', 'age' => 26);

//or, other synthax, same result
$foo = ['name' => 'John', 'Family' => 'Jeferson', 'age' => 26];

But you will not have all methods related to collections. But you can loop in it, and some basic stuff.

1 like

Please or to participate in this conversation.