由于这个解决方案是从其他地方投票充分的答案改编而来的,我没想到会遇到问题。
问题:我想使用 file1.csv file0.csv。LEFT JOIN
文件0.csv
+-----------------+-------------+--------------+
| Manufacturer ID | image | description |
+-----------------+-------------+--------------+
| SKU231 | image1.jpg | A box. |
| SKUAG1 | image22.jpg | Another box. |
| SKU21D | image7a.png | A third box. |
+-----------------+-------------+--------------+
文件1.csv:
+--------+--------+--------+-------+-------+
| mpn | length | height | width | title |
+--------+--------+--------+-------+-------+
| SKU231 | 22 | 14 | 10 | Box 1 |
| SKUAG1 | 12 | 6 | 6 | Box 2 |
| SKU21D | 5 | 8 | 5 | Box 3 |
+--------+--------+--------+-------+-------+
所需结果(文件2.csv):
+-----------------+-------------+--------------+--------+--------+--------+-------+-------+
| Manufacturer ID | image | description | mpn | length | height | width | title |
+-----------------+-------------+--------------+--------+--------+--------+-------+-------+
| SKU231 | image1.jpg | A box. | SKU231 | 22 | 14 | 10 | Box 1 |
| SKUAG1 | image22.jpg | Another box. | SKUAG1 | 12 | 6 | 6 | Box 2 |
| SKU21D | image7a.png | A third box. | SKU21D | 5 | 8 | 5 | Box 3 |
+-----------------+-------------+--------------+--------+--------+--------+-------+-------+
PHP 函数分别与 on 和:LEFT JOINfile0.csvfile1.csvManufacturer IDmpn
function my_csv_join(array $csv_input_file_array, $csv_output_file, $html_preview, $left_join_on, $right_join_on = NULL ){
if(count($csv_input_file_array) > 2){echo 'This function probably only works for 2 csv files being joined at a time. Reapply iteratively if needed. Exiting now.'; exit;}
}
}
慕妹3146593