dopa53272 2013-03-30 20:59
浏览 49
已采纳

两个阶段的in_array检查问题,不允许处理第二个语句

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

  • 写回答

3条回答 默认 最新

  • duandou8120 2013-04-02 22:29
    关注

    I have answered my own question by rethinking the logic behind the checks.
    Thank you for all your responses.

    Here is a link to the solution. I have posted it online to share as well as optimize, because all the great minds of SO deserve it!

    https://stackoverflow.com/questions/15775444/entry-of-items-checking-sharing-optimization-from-post-form

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据