Skip to content

Commit 3d12330

Browse files
committed
Fixed toFlat() method
1 parent b3f2c7a commit 3d12330

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/Classes/ExportLocalizations.php

+17-9
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,28 @@ public function toArray()
117117
*/
118118
public function toFlat( $array = [], $prefix = '' )
119119
{
120-
$array = ( count( $array ) ) ? $array : $this->strings;
121-
$result = [];
120+
function flatten( $array = [], $prefix = '', $default = [] )
121+
{
122122

123-
foreach ( $array as $key => $value ) {
124-
$new_key = $prefix . ( empty( $prefix ) ? '' : '.' ) . $key;
123+
$array = ( count( $array ) ) ? $array : $default;
124+
$result = [];
125125

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+
}
130134
}
135+
136+
return $result;
131137
}
132138

133-
return $result;
139+
$results = flatten( $array, $prefix, $this->strings );
140+
141+
return $results;
134142
}
135143

136144
public function toJson()

0 commit comments

Comments
 (0)