- var_dump: documentation ( source)
- array_combine: documentation ( source)
- array_column: documentation ( source)
- preg_match_all: documentation ( source)
<?php
//$contents = file_get_contents($path);
$contents = "sku-vendeur quantit prix id-produit
10000 3 51,95 B00E3LV204
10002 3 85,96 B00PE9ZC1E
100024 3 345,73 B01LWMZ33O
100031 3 88,22 B018NOSAZ6";
preg_match_all("/^(.*?)\s+(.*?)\s+(.*?)\s+(.*?)$/m", $contents, $arr);
unset($arr[0]); // remove 0 since we don't need it.
$keys = array_column($arr, 0);
foreach($arr[1] as $key2 => $val){
if($key2 != 0){
$new[] = array_combine($keys,array_column($arr, $key2));
}
}
var_dump($new);