Background:
I am creating a method to pull information from one table, check if it exists in a second table, and if it doesn't then insert the information. While comparing the data, the check must first see if the name matches, and then proceed to check if the account number matches the corresponding name. This code is heavily commented so a step by step process can be followed as well. I am greatly appreciative of all the help the masters of stackexchange bring to the table, so after scratching my head for a while, I bring my issues to the table.
Apparently my code is breaking when it goes to check the account number, even though a matching name exists. According to my best skills, all the code should work perfectly.
As you will be able to see through the print_f of all_validation_names, as well as all_validation_accounts, the information of the first passing statement is contained in the array with a check.
My question is as follows: Why can't a varchar variable, stored in an array with a corresponding key ($check_account_number) be passed into in_array. The function always returns else, where although the variable is "1", it isn't found using the corresponding key in $all_validation_accounts.
Please help!
Code For The Processing Of The Script
if (in_array($check_agency_name,$all_validation_names))
{
//Set a marker for the key index on which row the name was found
$array_key= array_search($check_agency_name, $all_validation_names);
//Now check if the account corresponds to the right account name
if (in_array($check_account_number,$all_validation_accounts["$array_key"]))
//NOTE: i've even tried strict comparison using third parameter true
{
//Bounce Them If the Account Matches with a name So theres no duplicate entry (works)
}
//If the account doesn't correspond to the right account name, enter the information
else
//ALSO DOESNT WORK: if (!(in_array($check_account_number,$all_validation_accounts["$array_key"])))
{
// The account doesn't exist for the name, so enter the information
//CODE TO ENTER INFORMATION THEN BOUNCE (works)
break;
}
}
The Output:
Passing Name to match: a And Account:1
There are accounts existing, so heres all the validation arrays: all_validation_names: Array ( [0] => a [1] => a [2] => b )
all validation accounts: Array ( [0] => 1 [1] => 2 [2] => 2 )
the system found check_agency_name in the array all_validation_names, so lets check the account number with this key: 0
the account name existed, but the system didn't find the account number match, so it must enter it as if the account never existed
heres the information that should be entered: used_selector: 0 agency_name:A address: city: state: zip: account_number: 1
now the system should enter the info, and bounce the client out