如何比较for循环中的登录信息

时间:2013-10-01 09:23:26

标签: php

这是我的登录功能代码:

for($i=0;$i<count($this->form['customer_info']);$i++)
{
    if($value['customer_id']==$this->form['customer_info'][$i]['customer_id'] && $value['customer_pw']==$this->form['customer_info'][$i]['customer_password'])
    {
        //my code
    }
    else
    {
        //my code
    }
}

这是里面的值:$ this-&gt; form ['customer_info']:

Array
(
[0] => Array
    (
        [customer_id] => 1
        [customer_company] => 123
        [customer_email] => 123@123.com
        [billing_address] => 
        [contact_info] => 
        [customer_password] => k41Y6fgW
    )

[1] => Array
    (
        [customer_id] => 2
        [customer_company] => abc
        [customer_email] => abc@abc.com
        [billing_address] => 
        [contact_info] => 
        [customer_password] => XwhcCWdx
    )

[2] => Array
    (
        [customer_id] => 3
        [customer_company] => 345
        [customer_email] => 345@345.com
        [billing_address] => 
        [contact_info] => 
        [customer_password] => gaKp3b5K
    )
)

只能验证第一个数组[0]的信息,其余的不是.. 我真的不知道那个.. 请帮助我...非常感谢!

1 个答案:

答案 0 :(得分:0)

您应该检查$value['customer_id']中的值是否与$info['customer_id']中的结果相同。如果它们是相同的(确保它们的顺序相同),那么检查$this->form['customer_info']的计数是否真的大于0.如果所有这些都不起作用,请尝试使用Shikiryu建议的foreach。

foreach($this->form['customer_info'] as $info) {
    if($value['customer_id'] == $info['customer_id'] && $value['customer_pw'] == $info['customer_password']) {
        //your code
    } else {
        //your code
    } 
}