Created
October 8, 2016 04:55
-
-
Save merin83/c957dea47f85c1d492fb7ef8206e3864 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $filename = 'snippets.json'; | |
| $f = file_get_contents( $filename ); | |
| $data = json_decode( $f, true ); | |
| echo "<pre>"; | |
| convertJSONtoArray( $data, 0 ); | |
| echo "</pre>"; | |
| function convertJSONtoArray( $data, $level ) // level - уровень вложенности чтобы табуляцию писать правильную | |
| { | |
| foreach( $data as $key1 => $value1 ) | |
| { | |
| if( is_array( $value1 ) ) | |
| { | |
| echo str_repeat( "\t", $level ) . '["' . $key1 . '"] => array (' . "\n"; | |
| convertJSONtoArray( $value1, $level + 1 ); | |
| echo str_repeat( "\t", $level ) . ")," . "\n"; | |
| } | |
| else | |
| { | |
| if( ( $value1=='true' ) or ( $value1=='false' ) or ( is_numeric( $value1 ) ) ) // if numeris or boolean we dont'add quotes | |
| { | |
| echo str_repeat( "\t", $level ) . '["' . $key1 . '"] => ' . $value1 . ',' . "\n"; | |
| } | |
| else | |
| { | |
| echo str_repeat( "\t", $level ) . '["' . $key1 . '"] => "' . $value1 . '",' . "\n"; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment