未定义的偏移PHP [英] Undefined Offset PHP

查看:74
本文介绍了未定义的偏移PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试执行代码时收到以下错误。

I am receiving the following error when I try to execute my code.

Notice (8): Undefined offset:  18 [APP/libs/excel_adapters/coverage.php, line 12]
Notice (8): Undefined offset:  23 [APP/libs/excel_adapters/coverage.php, line 13]
Notice (8): Undefined offset:  24 [APP/libs/excel_adapters/coverage.php, line 14]
Notice (8): Undefined offset:  25 [APP/libs/excel_adapters/coverage.php, line 15]
Notice (8): Undefined offset:  26 [APP/libs/excel_adapters/coverage.php, line 16]
Notice (8): Undefined offset:  14 [APP/libs/excel_adapters/coverage.php, line 17]
Notice (8): Undefined offset:  14 [APP/libs/excel_adapters/coverage.php, line 18]

这样,此代码用于将电子表格上传到数据库。我认为我的问题在于$ s变量。如果有人愿意,请看一下我的代码并告诉我我的问题是什么。我认为新鲜的眼睛会极大地帮助我。

With that said, this code is used to upload a spreadsheet to a database. I think my problem is with the $s variable. If someone would please take a look at my code and tell me what my problem is. I think a fresh set of eyes would help me tremendously.

      <?php 
      class CoverageExcelAdapter {

    public function extract($s, $args = array()) { 
    App::import('component', 'CakeSession');        
    $userId = CakeSession::read('Auth.User.id');        
    $ret = array();

    $ret['Coverage'] = array(
        'name' => $s[0][12][3], 
        'effective_date' => $this->Date->formatDate($s[0][18][3]),
        'expiration_date' => $this->Date->formatDate($s[0][18][6]),
        'broker_first_name' => ucwords($s[0][23][3]),
        'broker_middle_initial' => strtoupper(substr($s[0][24][3], 0, 1)),
        'broker_last_name' => ucwords($s[0][25][3]),
        'broker_suffix' => ucwords($s[0][26][3]),
        'producing_id' => $this->State->stateStrToId($s[0][14][3]), 
        'filing_id' => $this->State->stateStrToId($s[0][14][6]),

这是我的var转储...。

here is my var dump....

array(1) {
    [0]=> array(1) {
        [0]=> array(41) {
            [0]=> string(13) "ProcessorName"
            [1]=> string(10) "BranchCode"
            [2]=> string(9) "FileTaxID"
            [3]=> string(9) "FileState"
            [4]=> string(11) "FileLicense" [5]=> string(5) "First" [6]=> string(6) "Middle" [7]=> string(12) "Company_Last" [8]=> string(11) "InsuredName" [9]=> string(12) "RiskLocation" [10]=> string(14) "UnderwritingCo" [11]=> string(10) "Home State" [12]=> string(8) "PolicyNo" [13]=> string(10) "PolicyType" [14]=> string(10) "MultiState" [15]=> string(14) "LineOfBusiness" [16]=> string(13) "EffectiveDate" [17]=> string(24) "EndorsementEffectiveDate" [18]=> string(7) "EndDate" [19]=> string(7) "Premium" [20]=> string(13) "InsuredAmount" [21]=> string(9) "PolicyFee" [22]=> string(13) "InspectionFee" [23]=> string(6) "CatFee" [24]=> string(7) "SLTaxes" [25]=> string(17) "Fire Marshall Tax" [26]=> string(9) "Surcharge" [27]=> string(21) "Additional Assessment" [28]=> string(11) "StampingFee" [29]=> string(9) "InvoiceNo" [30]=> string(11) "InvoiceDate" [31]=> string(4) "AC1 " [32]=> string(8) "AC1 Date" [33]=> string(12) "AC1_Comments" [34]=> string(3) "AC2" [35]=> string(8) "AC2 Date" [36]=> string(12) "AC2_Comments" [37]=> string(3) "AC3" [38]=> string(8) "AC3 Date" [39]=> string(12) "AC3_Comments" [40]=> string(8) "Comments"
        }
    }
}

运行print_r

print_r

Array (
    [0] => Array (
        [0] => Array (
            [0] => ProcessorName
            [1] => BranchCode
            [2] => FileTaxID
            [3] => FileState
            [4] => FileLicense [5] => First [6] => Middle [7] => Company_Last [8] => InsuredName [9] => RiskLocation [10] => UnderwritingCo [11] => Home State [12] => PolicyNo [13] => PolicyType [14] => MultiState [15] => LineOfBusiness [16] => EffectiveDate [17] => EndorsementEffectiveDate [18] => EndDate [19] => Premium [20] => InsuredAmount [21] => PolicyFee [22] => InspectionFee [23] => CatFee [24] => SLTaxes [25] => Fire Marshall Tax [26] => Surcharge [27] => Additional Assessment [28] => StampingFee [29] => InvoiceNo [30] => InvoiceDate [31] => AC1 [32] => AC1 Date [33] => AC1_Comments [34] => AC2 [35] => AC2 Date [36] => AC2_Comments [37] => AC3 [38] => AC3 Date [39] => AC3_Comments [40] => Comments
        )
    )
)


推荐答案

在该方法内执行 var_dump($ s)。您正在访问不存在的数组键。

Do a var_dump($s) inside that method. You're accessing array keys that don't exist.

edit

鉴于上面的转储,您应该使用:

given your dumps above, you should be using:

$s[0][0][whatever]

。您已经将数组嵌套了3个层次,但是最外面的两层是单元素数组,例如

instead. You've got arrays nested 3 levels deep, but the outer two layers are single-element arrays, e.g.

$s = array(array(array("Processor Name", etc...)));

这篇关于未定义的偏移PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆