$rule) { if($headers_printed==false) { $header_str=""; $headers_printed=true; foreach($rule as $header=>$val) { if($header=='product_id') { $header_str.= $header.","; } else { $header_str.= $header.","; } } echo rtrim($header_str,',').PHP_EOL; } $val_str=""; foreach($rule as $key=>$val) { if(is_array($val)) { foreach($val as $k=>$v) { $val_str.=$v."<=".$k.":"; } $val_str=rtrim($val_str,":").","; } elseif(empty($val)) { $val_str.="NULL,"; } else { $val_str.=$val.","; } } echo rtrim($val_str,",").PHP_EOL ; } exit; } }