Skip to content

Instantly share code, notes, and snippets.

@mingyun
Created January 22, 2014 08:34
Show Gist options
  • Save mingyun/8555348 to your computer and use it in GitHub Desktop.
Save mingyun/8555348 to your computer and use it in GitHub Desktop.
php编辑配置文件ini格式文件
function put_ini_file ( $file , $array , $i = 0 ){
$str = "" ;
foreach ( $array as $k => $v ){
if ( is_array ( $v )){
$str .= str_repeat ( " " , $i * 2 ). "[ $k ]" . PHP_EOL ;
$str .= put_ini_file ( "" , $v , $i + 1 );
}else
$str .= str_repeat ( " " , $i * 2 ). " $k = $v " . PHP_EOL ;
}
if( $file )
return file_put_contents ( $file , $str );
else
return $str ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment