A few years ago the code was slightly modified to look a little better.
<?PHP/** * PHP array to TOML * * Beiliwenxiao * * 2014_07_09 First DRAFT * 2017_06_27 Modify * **/$show= "";functionGETTOML ($arr,$title= ""){ Global $show; if(Is_array($arr)) { foreach($arr as $key=$value) { if(Is_array($value)) { $show. = "\ r \ n"; if(!Empty($title)) { $show.= "[" .$title. ‘.‘ .$key. "]\r\n"; } Else { $show.= "[" .$key. "]\r\n"; } $show. = GETTOML ($value,$key); } Else if(!Empty($value) ||$value===false) { $show. = "\ r \ n"; $show.=$key. "=\"" . Getrightstring ($value) . "\" \ r \ n "; } } }}functionGetrightstring ($str){ $value=$str; if($value===true) { $value= "true"; } if($value===false) { $value= "false"; } $value=addslashes($value); $value=Str_replace("\‘", "‘",$value); return $value;}$test={"Dog": {"Onekey": "Onevalue", "Tater": {"type": "Pug" }}}‘;$test= Json_decode ($test,true); GETTOML ($test);Echo $show;
PHP Array goto TOML