Q:

How to compare login information in a for loop

This is my code for a login function:
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
    }
}

and this is the values inside: $this->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
    )
)

Only the information of first array[0] is able to be verified, the rest are not..
I really have no idea of that..
Please help me... Many many thanks!

A:

you should check if the values in $value['customer_id'] is the same as the result in $info['customer_id']. If they are the same (make sure they are in the same order), then check if the count of $this->form['customer_info'] is really more than 0. if all this is not working, try to use a foreach as suggested by Shikiryu.
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
    } 
}

