Home > Enterprise >  how do i get the users from this array?
how do i get the users from this array?

Time:05-18

Array ( [message] => Array ( [users] => Array ( [0] => Array ( [_id] => 62698b2354332572fa00abf9 [first_name] => Messi [last_name] => Kaka [email] => [email protected] [role] => admin [status] => active [__v] => 0 ) [1] => Array ( [_id] => 626cba0b2bd4b5fa484ba8b2 [avatar] => 194.195.214.39/api/images/default.svg [first_name] => Sunny [last_name] => Ojo [email] => [email protected] [role] => admin [status] => active [__v] => 0 ) [2] => Array ( [_id] => 626d89972bd4b5fa484ba936 [avatar] => 194.195.214.39/api/images/default.svg [first_name] => bola [last_name] => ahmed [email] => [email protected] [role] => member [status] => active [__v] => 0 ) [3] => Array ( [_id] => 626d8fe82bd4b5fa484ba939 [avatar] => 194.195.214.39/api/images/default.svg [first_name] => bola [last_name] => ahmed [email] => [email protected] [role] => member [status] => active [__v] => 0 ) [4] => Array ( [_id] => 626d9d4f2bd4b5fa484ba93c [avatar] => 194.195.214.39/api/images/default.svg [first_name] => bola [last_name] => ahmed [email] => [email protected] [role] => member [status] => active [__v] => 0 ) ) [totalItems] => 12 [hasNextPage] => 1 [hasPreviousPage] => [lastPage] => 3 ) [success] => 1 )

CodePudding user response:

$users = $array['message']['users'];

CodePudding user response:

If I understand this question right, then this should help:

  1. Preformat it like this:
<?php
$data = [
    'message' => [
        'users' => [
            0 => [
                '_id' => '62698b2354332572fa00abf9',
                'first_name' => 'Messi',
                'last_name' => 'Kaka',
                'email' => '[email protected]',
                'role' => 'admin',
                'status' => 'active',
                '__v' => 0,
            ],
            1 => [
                '_id' => '626cba0b2bd4b5fa484ba8b2',
                'avatar' => '194.195.214.39/api/images/default.svg',
                'first_name' => 'Sunny',
                'last_name' => 'Ojo',
                'email' => '[email protected]',
                'role' => 'admin',
                'status' => 'active',
                '__v' => 0,
            ],
            2 => [
                '_id' => '626d89972bd4b5fa484ba936',
                'avatar' => '194.195.214.39/api/images/default.svg',
                'first_name' => b'ola',
                'last_name' => 'ahmed',
                'email' => '[email protected]',
                'role' => 'member',
                'status' => 'active',
                '__v' => 0,
            ],
            3 => [
                '_id' => '626d8fe82bd4b5fa484ba939',
                'avatar' => '194.195.214.39/api/images/default.svg',
                'first_name' => 'bola',
                'last_name' => 'ahmed',
                'email' => '[email protected]',
                'role' => 'member',
                'status' => 'active',
                '__v' => 0
            ],
            4 => [
                '_id' => '626d9d4f2bd4b5fa484ba93c',
                'avatar' => '194.195.214.39/api/images/default.svg',
                'first_name' => 'bola',
                'last_name' => 'ahmed',
                'email' => '[email protected]',
                'role' => 'member',
                'status' => 'active',
                '__v' => 0
            ],
        ],
        'totalItems' => 12,
        'hasNextPage' => 1,
        'hasPreviousPage' => null,
        'lastPage' => 3,
    ],
    'success' => 1,
];
  1. Run this line to access users as an array of data:
var_dump($data['message']['users']);

  •  Tags:  
  • php
  • Related