function override_recursive_helper($key_names, $array_name, $value) { if (empty($key_names)) { return "=" . var_export_helper($value, true) . ";"; } else { $key = array_shift($key_names); return "[" . var_export($key, true) . "]" . override_recursive_helper($key_names, $array_name, $value); } }
public function testoverride_recursive_helper() { //execute the method and test if it returns expected values //without keys $tempArray = array('Key1' => 'value1', 'Key2' => 'value2'); $expected = "=array (\n 'Key1' => 'value1',\n 'Key2' => 'value2',\n);"; $actual = override_recursive_helper('', 'tempArray', $tempArray); $this->assertSame($actual, $expected); //with keys $tempArray = array(); $tempArray['Key1']['Key2'] = array('Key3' => 'value', 'Key4' => 'value'); $expected = "['key1']['key2']=array (\n 'Key1' => \n array (\n 'Key2' => \n array (\n 'Key3' => 'value',\n 'Key4' => 'value',\n ),\n ),\n);"; $actual = override_recursive_helper(array('key1', 'key2'), 'tempArray', $tempArray); $this->assertSame($actual, $expected); }