return $array;
}
+ /**
+ * Append the value to the array using the key provided.
+ *
+ * e.g if value is 'llama' & path is [0, 'email', 'location'] result will be
+ * [0 => ['email' => ['location' => 'llama']]
+ *
+ * @param $path
+ * @param $value
+ *
+ * @return array
+ */
+ public static function recursiveBuild($path, $value) {
+ $arrayKey = array_shift($path);
+ return [$arrayKey => (empty($path) ? $value : self::recursiveBuild($path, $value))];
+ }
+
}
$this->assertEquals($expected, $result);
}
+ /**
+ * Get values for build test.
+ */
+ public function getBuildValueExamples() {
+ return [
+ [
+ [0, 'email', 2, 'location'], [0 => ['email' => [2 => ['location' => 'llama']]]]
+ ]
+ ];
+ }
+
+ /**
+ * Test the build recursive function.
+ *
+ * @param $path
+ * @param $expected
+ *
+ * @dataProvider getBuildValueExamples
+ */
+ public function testBuildRecursiveValue($path, $expected) {
+ $result = CRM_Utils_Array::recursiveBuild($path, 'llama');
+ $this->assertEquals($expected, $result);
+ }
+
}