0

我的mysql数据库上有这个

email have 5 value
user have 15 value

我怎么能用这样的东西循环电子邮件

email          user
ya1@yahoo.com  user1
ya2@yahoo.com  user2
ya3@yahoo.com  user3
ya4@yahoo.com  user4
ya5@yahoo.com  user5
ya1@yahoo.com  user6
ya2@yahoo.com  user7
ya3@yahoo.com  user8
--------------------
and so on....

使用 php foreach ......就像当用户循环时,电子邮件值也会循环,当它到达电子邮件值的末尾时,电子邮件将再次开始到第一个 ya1@yahoo.com

是否有可能在 foreach 上进行这项工作或暂时进行?

4

3 回答 3

0
$data = array();
$i=0;
foreach($users as $user){
if(isset($email[$i])){
$data[$email[$i]] = $user;
}
else{
$i=0;
$data[$email[$i]] = $user;

}
$i++;
}
print_r($data);
于 2012-08-26T13:12:06.767 回答
0

像这样的东西:

$j=0;
for ($i=0;$i<count($users);$i++){
    if (count($email)<$j+1)
        $j=0;
    else
        $j++;
echo $users[$i].' has email: '.$email[$j];
}
于 2012-08-26T13:12:24.167 回答
0
$e = array('email1', 'email2' /* , more email */);
$u = array('user1', 'user2', 'user3' /* , more users */);

$total_e = count($e);
$total_u = count($u);
$total   = $total_e * $total_u;

$counting_e  = 0;
$counting_u  = 0;

for ($i = 0; $i < $total; $i ++ )
{
    echo nl2br($e[$counting_e ++] . " => " . $u[$counting_u ++] . "\n");

    if ($counting_e == $total_e)
        $counting_e = 0;
    if ($counting_u == $total_u)
        $counting_u = 0;
}

测试:http ://codepad.org/R5PpAKQW

于 2012-08-26T13:27:34.573 回答