PHP数组注意未定义的索引 - 它定义了什么?

时间:2014-11-17 13:59:49

标签: php arrays

我的问题包围了我的意思,我的意思应该可以正常工作。

以下是代码:

        foreach( $_POST['wageline'] AS $line ){
            print_r( $line );
            if( !$MySQL->Query(" 
                INSERT INTO
                    wages_lines
                SET
                    'batch_id' = '" . $this->batch_id . "',
                    'name' = '" . $line['name'] . "',
                    'identity_number' = " . $line['identity_number'] . "',
                    'account' = '" . $line['account'] . "',
                    'phone' = '" . $line['phone'] . "',
                    'ordinary_hours' = '" . $line['ordinary_hours'] . "',
                    'fifty_percent' = '" . $line['fifty_percent'] . "',
                    'hundred_percent' = '" . $line['hundred_percent'] . "',
                    'mileage' = '" . $line['mileage'] . "',
                    'remuneration' = '" . $line['remuneration'] . "',
                    'pall_dag_2' = '" . $line['pall_dag_2'] . "',
                    'pall_dag_3' = '" . $line['pall_dag_3'] . "',
                    'pall_natt_2' = '" . $line['pall_natt_2'] . "',
                    'pall_natt_3' = '" . $line['pall_natt_3'] . "',
                    'ub_1' = '" . $line['ub_1'] . "',
                    'ub_2' = '" . $line['ub_2'] . "',
                    'ub_3' = '" . $line['ub_3'] . "',
                    'ub_4' = '" . $line['ub_4'] . "',
                    'ub_5' = '" . $line['ub_5'] . "',
                    'employee_wage' = '" . $line['employee_wage'] . "',
                    'brutto_total' = '" . $line['brutto_total'] . "',
                    'mileage_total' = '" . $line['mileage_total'] . "',
                    'remuneration_total' = '" . $line['remunerations_total'] . "'
            ") )

我的print_r的结果如下:

Array
(
['name'] => Alexander Fagerstrand
['identity_number'] => 
['account'] => 
['phone'] => 0
['ordinary_hours'] => 32.5
['fifty_percent'] => 0
['hundred_percent'] => 0
['mileage'] => 458
['remuneration'] => 628
['pall_dag_2'] => 0
['pall_dag_3'] => 0
['pall_natt_2'] => 0
['pall_natt_3'] => 0
['ub_1'] => 0
['ub_2'] => 0
['ub_3'] => 0
['ub_4'] => 0
['ub_5'] => 0
['employee_wage'] => 177
['brutto_total'] => 5752.50
['mileage_total'] => 1854.9
['remunerations_total'] => 628
)

然而,我正在收到通知:


    通知:未定义索引: /var/www/vhosts/ontimebemanning.no/portal.ontimebemanning.no/modules/core.wages/classes/wage.class.php 在线 573

    通知 /var/www/vhosts/ontimebemanning.no/portal.ontimebemanning.no/modules/core.wages/classes/wage.class.php 在线 574

显然,它们是定义的,所以我不知道为什么我的剧本会在我的脸上投下通​​知。 有人知道吗?

2 个答案:

答案 0 :(得分:4)

如果这是print_r()的输出,则POST请求中发送的数据在键名称周围有引号;现在你必须这样做才能访问数据:

echo $lines["'name'"];

或者,更优选地,找出转移这些额外报价的原因并将其删除。

答案 1 :(得分:0)

您的代码中有错误。您在查询代码中使用的是=>而不是=