File tree 1 file changed +17
-9
lines changed
1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -117,20 +117,28 @@ public function toArray()
117
117
*/
118
118
public function toFlat ( $ array = [], $ prefix = '' )
119
119
{
120
- $ array = ( count ( $ array ) ) ? $ array : $ this -> strings ;
121
- $ result = [];
120
+ function flatten ( $ array = [], $ prefix = '' , $ default = [] )
121
+ {
122
122
123
- foreach ( $ array as $ key => $ value ) {
124
- $ new_key = $ prefix . ( empty ( $ prefix ) ? '' : ' . ' ) . $ key ;
123
+ $ array = ( count ( $ array ) ) ? $ array : $ default ;
124
+ $ result = [] ;
125
125
126
- if ( is_array ( $ value ) ) {
127
- $ result = array_merge ( $ result , $ this ->toFlat ( $ value , $ new_key ) );
128
- } else {
129
- $ result [ $ new_key ] = $ value ;
126
+ foreach ( $ array as $ key => $ value ) {
127
+ $ new_key = $ prefix . ( empty ( $ prefix ) ? '' : '. ' ) . $ key ;
128
+
129
+ if ( is_array ( $ value ) ) {
130
+ $ result = array_merge ( $ result , flatten ( $ value , $ new_key ) );
131
+ } else {
132
+ $ result [ $ new_key ] = $ value ;
133
+ }
130
134
}
135
+
136
+ return $ result ;
131
137
}
132
138
133
- return $ result ;
139
+ $ results = flatten ( $ array , $ prefix , $ this ->strings );
140
+
141
+ return $ results ;
134
142
}
135
143
136
144
public function toJson ()
You can’t perform that action at this time.
0 commit comments