2012-08-08 52 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