数组数据如何存储在会话中

I have a challenge in getting back the array i stored in a session. I stored the array in a array like this

$downlines = '2,3,4,5,6,7,8';
$_SESSION['downline'] = $afrisoft->dbarray("SELECT username, email FROM users WHERE id IN $downlines")

When i print_r the session i get this

Array (
      [0] => Array (
                   [username] => mcbel 
                   [email] => firstmail@gmail.com
                   )
      [1] => Array (
                   [username] => bimibola
                   [email] => secondmail@yahoo.com
                   )
      [2] => Array (
                   [username] => shadie
                   [email] => thirdmail@gmail.com
                   )
      [3] => Array (
                   [username] => Hifee
                   [email] => ife@ife.net
                   )
      )

What i intend to achieve is to get the data stored in ['usernmae'] and ['email'], however when i try to print_r($_SESSION['downline']['username']) and print_r($_SESSION['downline']['email']) it returns no values.

I'll appreciate any help i can get on this.

You have an array that is returned by your function. you can access the first element of that array by $_SESSION['downline'][0]['username']

you can access the full results by traversing through $_SESSION['downline'] by doing

foreach ($_SESSION['downline'] as $item) {
   echo $item['username']
} 
<?php

foreach($_SESSION['downline'] as $userDetails){
    echo $userDetails['username'];
}