简单的问题......但在这里:
我有一个数组,我需要使用[0]索引来表示每个用户的id。但我似乎无法在foreach声明中得到它。
$emails = $aTools->getUsers();
以下是上述数组的print_r' $ emailils'。
Array
(
[0] => Array
(
[0] => 72
[1] =>
[2] => email@yahoo.com
)
[1] => Array
(
[0] => 62
[1] =>
[2] => email@gmail.com
)
[2] => Array
(
[0] => 64
[1] =>
[2] => email@gmail.com
)
[3] => Array
(
[0] => 66
[1] =>
[2] => email@yahoo.com
)
)
这不起作用
$i = 0;
foreach($emails as $email)
{
echo $email[$i][0];
echo "<br/>";
$i++;
}
答案 0 :(得分:0)
每次你循环,你都会在条目表上收到$ email:
Array
(
[0] => 72
[1] =>
[2] => email@yahoo.com
)
然后
Array
(
[0] => 62
[1] =>
[2] => email@gmail.com
)
ETC ..
所以echo $ email [$ i] [0]无法返回你想要的id。
$ email [0] CAN。
解决方案:
foreach($emails as $email)
echo $email[0];