I have a small problem with my recursive function, and it is that FQDN is not being created correctly.
public function testBuildReverseSchemaNames() {
$input = [
'propertyZeroSchema' => 'value_0',
'communicationPreferences' => [
'grv3_newsletter_bi' => true
],
'someContainer' => [
'propertyOneSchema' => 'value_1'
],
'propertyThreeSchema' => 'value_3'
];
$expected = [
'propertyZeroSchema' => 'value_0',
'communicationPreferences.grv3_newsletter_bi' => true,
'someContainer.propertyOneSchema' => 'value_1',
'propertyThreeSchema' => 'value_3'
];
$output = [];
$this->buildReverseSchemaNames($input, $output);
$this->assertEquals($expected, $output);
}
public function buildReverseSchemaNames($data, &$output, $currentFqdn = '') {
foreach ($data as $key => $value) {
if (is_array($value)) {
$currentFqdn .= $key.'.';
$this->buildReverseSchemaNames($value, $output, $currentFqdn);
} else {
$currentFqdn .= $key;
$output[$currentFqdn] = $value;
}
}
}
But the output is like this:
Array (
'propertyZeroSchema' => 'value_0'
'propertyZeroSchemacommunicationPreferences.grv3_newsletter_bi' => true
'propertyZeroSchemacommunicationPreferences.someContainer.propertyOneSchema' => 'value_1'
'propertyZeroSchemacommunicationPreferences.someContainer.propertyThreeSchema' => 'value_3'
)