<?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;
preferences:
78.57 ms | 406 KiB | 5 Q