0

我在取回存储在会话中的数组时遇到了挑战。我将数组存储在这样的数组中

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

当我 print_r 会话时,我得到了这个

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
                   )
      )

我打算实现的是获取存储在['usernmae']and中的数据['email'],但是当我尝试时print_r($_SESSION['downline']['username'])print_r($_SESSION['downline']['email'])没有返回任何值。

我会很感激我能得到的任何帮助。

4

2 回答 2

1

您有一个由您的函数返回的数组。您可以通过以下方式访问该数组的第一个元素$_SESSION['downline'][0]['username']

$_SESSION['downline']您可以通过遍历来访问完整的结果

foreach ($_SESSION['downline'] as $item) {
   echo $item['username']
} 
于 2013-07-24T10:20:46.803 回答
1
<?php

foreach($_SESSION['downline'] as $userDetails){
    echo $userDetails['username'];
}
于 2013-07-24T10:21:56.007 回答