0

我试图让这段代码工作,因为它正是我所追求的: http ://www.reloadedpc.com/php/php-convert-csv-price-matrix-mysql-table/

虽然我收到此错误:

警告:array_merge() [function.array-merge]:参数 #1 不是第 580 行 C:\xampp\htdocs\matrix\Csv.php 中的数组

警告:array_merge() [function.array-merge]:参数 #1 不是第 580 行 C:\xampp\htdocs\matrix\Csv.php 中的数组

警告:array_merge() [function.array-merge]:参数 #1 不是第 580 行 C:\xampp\htdocs\matrix\Csv.php 中的数组

致命错误:无法访问第 24 行 C:\xampp\htdocs\matrix\index.php 中的受保护属性 Csv::$field_names

第 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

有什么建议么?

多谢你们。

-EDIT- 整个代码块是:

 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] 是矩阵的标题。

4

1 回答 1

1

如果您查看错误的最后一行,它会显示:

致命错误:无法访问第 24 行 C:\xampp\htdocs\matrix\index.php 中的受保护属性 Csv::$field_names

现在转到您发布的 Csv.php 链接并查看代码,您会看到确实field_names定义为: protected $field_names = array();,这意味着您无法直接访问它,除非您扩展 Csv 类。

如果您不想扩展此类,只需使用公共方法:

$csv->get_field_names();
于 2012-08-08T09:10:16.690 回答