<?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);
- Output for 5.6.38, 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
- array(4) {
[0]=>
array(4) {
["sku-vendeur"]=>
string(0) ""
["quantit"]=>
string(5) "10000"
["prix"]=>
string(1) "3"
["id-produit"]=>
string(18) "51,95 B00E3LV204"
}
[1]=>
array(4) {
["sku-vendeur"]=>
string(0) ""
["quantit"]=>
string(5) "10002"
["prix"]=>
string(1) "3"
["id-produit"]=>
string(18) "85,96 B00PE9ZC1E"
}
[2]=>
array(4) {
["sku-vendeur"]=>
string(0) ""
["quantit"]=>
string(6) "100024"
["prix"]=>
string(1) "3"
["id-produit"]=>
string(18) "345,73 B01LWMZ33O"
}
[3]=>
array(4) {
["sku-vendeur"]=>
string(0) ""
["quantit"]=>
string(6) "100031"
["prix"]=>
string(1) "3"
["id-produit"]=>
string(18) "88,22 B018NOSAZ6"
}
}
preferences:
149.43 ms | 410 KiB | 5 Q