Advertisement
C_Volume2 Data Structures #84416

array-to-file

Code reads an array and writes array's php code to a file.

AI

AI 요약: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

소스 코드
original-source
<?
 /* Array to File */
 function __process_array($array,$indent)
 {
 $ret_str = "";
 $first = true;
 foreach ($array as $key => $value)
 {
  if (!$first) 
  $ret_str .= ",\n";
  else
  $first = false;
			
  $ret_str .= str_repeat(" ",$indent);
						
  if (is_array($value)) 
  {
  $ret_str .= "'$key' => array(\n".__process_array($value,$indent+5)."\n".str_repeat(" ",$indent).")";
  }
  elseif (is_string($value))
  {
  $ret_str .= "'$key' => '$value'";
  }
  elseif (is_int($value))
  {			
  $ret_str .= "'$key' => $value";
  }
  elseif (is_bool($value))
  {			
  $ret_str .= "'$key' => ".($value?"true":"false");
  }
 }
 return $ret_str;
 }
	
 function array_to_file($array,$name,$filename)
 {
 $file_str = "<?\n $"."$name = array(\n";
 $file_str .= __process_array($array,6);	
 $file_str .= "\n );\n?>";
		
 $file = fopen($filename,"w");
 fwrite($file,$file_str);
 fclose($file);
 }
?>
원본 댓글 (3)
Wayback Machine에서 복구됨