memo

memo dayo.

配列をTSVファイルとして書き込む


function ary2tsv ($file_name, $ary_param) {
$bol_return = False;

if (count($ary_param) === 0) {
return $bol_return;
}

if (is_file($file_name) === False) {
touch($file_name);
chmod($file_name, 0777);
}

$int_line = 0;
$fp = fopen($file_name, 'wb');
foreach ($ary_param as $index_1 => $value_1) {
$str_tmp = '';

// add title
if ($int_line === 0) {
$bol_2nd = False;
foreach ($value_1 as $index_2 => $value_2) {
if ($bol_2nd === False) {
$bol_2nd = True;
} else {
$str_tmp .= "\t";
}
$str_tmp .= $index_2;
}
$str_tmp .= "\n";
unset($bol_2nd);
$int_line++;
}

// add data
$bol_2nd = False;
foreach ($value_1 as $index_2 => $value_2) {
if ($bol_2nd === False) {
$bol_2nd = True;
} else {
$str_tmp .= "\t";
}
$str_tmp .= $value_2;
}
$str_tmp .= "\n";
unset($bol_2nd);

// write
fwrite($fp, $str_tmp);
unset($str_tmp);
}
fclose($fp);
unset($fp);
unset($int_line);

$bol_return = True;

return $bol_return;
}

広告を非表示にする