duanbo7517 2015-01-19 13:28
浏览 56

使用PHP将具有重复ID的特定单元格与CSV合并

My .csv has duplicate clubs throughout the whole file, creating 1500 rows, the reason for this is that each duplicate row is an additional ClubTDays, ClubTStartTime and ClubTFinishTime.

Meaning rather than write the club times in one cell, it has been exported with each new class duplicating the rest of the information.

This .csv. is imported into Wordpress using All Import, then the clubs are shown on a google map with the right information.

My issue is that it can say the same address 8-9 times because of the day/times over rows.

Question:

The ClubNumber is the id of the club. Is there a way with php to merge rows with the same ClubNumber, keep the address the same for these duplicates, but for the ClubTDays / ClubTStartTime/ClubTFinishTime differenciate, they're combined into one cell.

This way, the google map will only list the one address per club, but list several days that they opperate.


Here's some example code i'm working with:

$handle = fopen("CLUBEXP.csv", "r");

$row = 0;
$ClubNumberList = array();

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $ClubNumber = $data[0];
    $ClubTDays = $data[19];

    if ( array_key_exists($ClubNumber, $ClubNumberList) ) {
        $ClubNumberList[$ClubNumber][] = $ClubTDays;
    } else {
        $ClubNumberList[$ClubNumber] = array($ClubTDays);
    }
    $row++;
}

print_r( $ClubNumberList );

The issue with this code is that it removes all over columns. It merges the day fine, but it doesn't copy over the rest.

Once these fields have been merged, I need to save the .csv with a different name like "clubs-merged.csv" so I can import it through wordpress.

Can this be done? & Can anyone point me in the right direction?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)