Support the ongoing development of Laravel.io →
posted 9 years ago
Architecture

Can someone please explain this syntax with the arrays , what it does, what it means?

$response = [
            'users' => []
        ];
$users = $this->user->all()->take(9);

        foreach($users as $user){
//these right here
            $response['users'][] = [
                'id' => $user->id,
                'name' => $user->name,
                'username' => $user->username,
                'lastname' => $user->lastname
            ];
        }

$response = [
            'user' => []
        ];
        $user = $this->user->find($id);
//these right here      
$response = [
            'id' => $user->id,
            'name' => $user->name,
            'lastname' => $user->lastname,
            'username' => $user->username
        ];
Last updated 2 years ago.
0

you mean [] ?

since php 5.5 you can use array literal. (just like in js)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

teejten9 teejten9 Joined 3 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.