2012-08-08 31 views
0

我試圖讓這個代碼工作,因爲它正是我追求: http://www.reloadedpc.com/php/php-convert-csv-price-matrix-mysql-table/CSV矩陣到MySQL

雖然我得到這個錯誤:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\xampp\htdocs\matrix\Csv.php on line 580

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\xampp\htdocs\matrix\Csv.php on line 580

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\xampp\htdocs\matrix\Csv.php on line 580

Fatal error: Cannot access protected property Csv::$field_names in C:\xampp\htdocs\matrix\index.php on line 24

580線是以下Csv.php是:

$this->contents[$line_nr][(int) $position] = array_merge($this->contents[$line_nr][(int) $position]); 
的index.php的

和線24(和23)是:

//get the row of width increments 
$stack = $csv->field_names; 

的Csv.php文件可以在這裏看到: http://hg.mijnpraktijk.com/csv-library/src/e4397b31002d/Csv.php

有什麼建議?

謝謝你們。

CNC中 整個代碼塊是:

foreach ($this->contents as $line_nr => $line) 
       { 

         if (array_key_exists((int) $position, $this->contents[$line_nr])) 
         { 
          $return[$line_nr] = $this->contents[$line_nr][(int) $position]; 
           unset($this->contents[$line_nr][(int) $position]); 
           // reindex after removal 
           $this->contents[$line_nr][(int) $position] = array_merge($this->contents[$line_nr][(int) $position]); 
         } 
       } 

它似乎取消它。 $ this-> contents [$ line_nr] [(int)$ position]是矩陣的標題。

+0

你做任何調試,看看有什麼'$這個 - >內容[$ line_nr] [(INT)$位置]'實際上是? – 2012-08-08 08:59:44

+0

添加在原始帖子中 – user1380591 2012-08-08 09:07:57

回答

1

如果你看一下錯誤的最後一行,它說:

Fatal error: Cannot access protected property Csv::$field_names in C:\xampp\htdocs\matrix\index.php on line 24

現在去Csv.php鏈接您發佈並查看代碼,你會看到,確實field_names定義如:protected $field_names = array();,這意味着除非擴展Csv類,否則不能直接訪問它。

如果你不想繼承這個類只使用公有方法:

$csv->get_field_names(); 
+0

這解決了一半的問題。 – user1380591 2012-08-08 09:22:05

+0

這是什麼意思? – Tomer 2012-08-08 09:24:20