2012-07-24 94 views
0

我在嘗試執行我的代碼時收到以下錯誤。未定義抵消PHP

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變量。如果有人願意看看我的代碼,並告訴我我的問題是什麼。我認爲一個新的眼睛會幫助我很大。

 <?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]), 

這裏是我的變種轉儲....

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 
     ) 
    ) 
) 
+2

'$ s'是什麼? count($ s [0])是什麼? – 2012-07-24 14:38:52

+2

print_r你的$ s變量,它可能不需要格式化你認爲它的值。 – yent 2012-07-24 14:39:23

+1

您可以指導我們瞭解'$ s'的內容嗎? – JNF 2012-07-24 14:39:52

回答

3

做一個var_dump($s)該方法中。您正在訪問不存在的數組鍵。


編輯

上面給出你的場,你應該使用:

$s[0][0][whatever] 

代替。你有數組嵌套3層深,但外層是單元素數組,例如,

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

好....我做了一個var轉儲....我也做了一個print_r ....如果我發佈我的結果會有幫助 – 2012-07-24 15:08:17

+0

是的。我們無法告訴你如何訪問數組而不看數組中的內容。 – 2012-07-24 15:17:26

+0

好吧我編輯了我原來的帖子,並在那裏發佈了我的var轉儲 – 2012-07-24 15:20:34

1

轉儲變種通過其他的答案和評論的建議,看看哪些鍵是actualy擁有並定義好名字常量,這些偏移 - 它們意味着什麼?他​​們如何改變?這個代碼對任何程序員都沒有意義(你在幾天或幾周內就已經包含了)。