3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$str = file_get_contents("file.csv"); $str = "sku,is_in_stock,warehouse_3,warehouse_4 AP-STYLUS,0,20,5 RC-3049,0,0,0 NFNC-FLAT-CAP,0,20,20 NFNC-HOOD14-ZIP-S,1,0,5"; $arr = explode("\n", $str); $result = array(); Foreach($arr as $line){ $linearr = explode(",", $line); If(is_numeric($linearr[2])){ if($linearr[2]+$linearr[3]>=1){ $linearr[1]="1"; $line = implode("," , $linearr); }else{ $linearr[1]="0"; $line = implode("," , $linearr); } } $result[]=$line; } $newstr = implode("\n", $result); //put_file_contents("file.csv", $newstr); Echo $newstr;
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 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.30, 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
sku,is_in_stock,warehouse_3,warehouse_4 AP-STYLUS,1,20,5 RC-3049,0,0,0 NFNC-FLAT-CAP,1,20,20 NFNC-HOOD14-ZIP-S,1,0,5

preferences:
83.14 ms | 408 KiB | 5 Q