我使用php-csv-parser从 csv 文件转换了 2 个数组。这是最旧的文件:
Array
(
[0] => Array
(
[0] => A Single Man
[1] => Tom Ford
[2] => 2009
[3] => Somestring
)
[1] => Array
(
[0] => Bram Stoker Dracula
[1] => Francis F. Coppola
[2] => 1992
[3] => Somestring
)
)
这是最新的:
Array
(
[0] => Array //this is a new record
(
[0] => A Single Man
[1] => Tom Ford
[2] => 1988
)
[1] => Array //this record already exists in oldest array
(
[0] => A Single Man
[1] => Tom Ford
[2] => 2009
)
[2] => Array //this record already exists but has a modify
(
[0] => Bram Stoker Dracula
[1] => Francis Ford Coppola //modified string
[2] => 1992
)
)
我想创建第三个“合并”数组,其中包含新记录和修改后的字符串。请注意,如果Array[i][2]是不同的字符串,我必须创建一个新记录,但如果任何其他参数发生更改,只需修改记录。之后,对于每条新记录,我必须填写所有其他空参数。
这是预期的输出
Array
(
[0] => Array
(
[0] => A Single Man
[1] => Tom Ford
[2] => 1988
[3] => //empty for now, to fill
)
[1] => Array
(
[0] => A Single Man
[1] => Tom Ford
[2] => 2009
[3] => Somestring
)
[2] => Array
(
[0] => Bram Stoker Dracula
[1] => Francis Ford Coppola
[2] => 1992
[3] => Somestring
)
)