0

我有一个 PHP 数组,如下所示:

    Array
(
    [2] => Array
        (
            [_diskquota] => 524288000
            [_diskused] => 0
            [diskquota] => 500
            [diskused] => 0
            [diskusedpercent] => 0
            [diskusedpercent20] => 0
            [domain] => domain1.com
            [email] => aaa@domain1.com
            [humandiskquota] => 500 MB
            [humandiskused] => None
            [login] => aaa@domain1.com
            [mtime] => 1378636684
            [txtdiskquota] => 500
            [user] => aaa
        )

    [3] => Array
        (
            [_diskquota] => 0
            [_diskused] => 0
            [diskquota] => unlimited
            [diskused] => 0
            [diskusedpercent] => 0
            [diskusedpercent20] => 0
            [domain] => domain2.com
            [email] => ddd@domain2.com
            [humandiskquota] => None
            [humandiskused] => None
            [login] => ddd@domain2.com
            [mtime] => 1378636684
            [txtdiskquota] => unlimited
            [user] => ddd
        )

    [4] => Array
        (
            [_diskquota] => 104857600
            [_diskused] => 0
            [diskquota] => 100
            [diskused] => 0
            [diskusedpercent] => 0
            [diskusedpercent20] => 0
            [domain] => domain3.com
            [email] => sss@domain3.com
            [humandiskquota] => 100 MB
            [humandiskused] => None
            [login] => sss@domain3.com
            [mtime] => 1378636684
            [txtdiskquota] => 100
            [user] => sss
        )
)

如何在 php foreach 中获得这样的结果?(我不想列出其他值)

电子邮件 | 人类磁盘配额| 人类磁盘使用

我的尝试代码。foreach 正在运行,但我无法从数组中获取电子邮件值。

foreach ($d as $arr => $key)
{
foreach ($key as $k => $v)
{
//echo "$k: $v<br>";
echo $email=$k['email'].' | ';
echo $email=$v['email'].' | ';
echo $email=$v->email.' | ';
echo $email=$k->email.' | ';
}
echo "<br>";
}
4

2 回答 2

0

你可以简单地做到这一点foreach

foreach ($d as $array){
  echo "{$array['email']} | {$array['humandiskquota']} | {$array['humandiskused']} <br/>" ;
}
于 2013-09-08T13:29:18.327 回答
0

这里不需要两个foreach循环。以下应该有效:

foreach ($d as $key => $data) {
    $email[] = $data['email'];

    echo $data['email']. ' | ' . 
         $data['humandiskquota'] . ' | ' . 
         $data['humandiskused'];

    echo '<br/>';
}
//print_r($email);

输出:

aaa@domain1.com | 500 MB | None
ddd@domain2.com | None | None
sss@domain3.com | 100 MB | None

演示!

于 2013-09-08T13:44:18.697 回答