ENHANCEMENT Use array_combine() instead of custom logic for ArrayLib::valuekey() (thanks paradigmincarnate!)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@107380 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2010-07-01 05:12:43 +00:00 committed by Sam Minnee
parent eccf44ec64
commit a10bb202af
2 changed files with 17 additions and 5 deletions

View File

@ -62,11 +62,7 @@ class ArrayLib {
* @return array
*/
static function valuekey($arr) {
$newArr = array();
foreach($arr as $val) {
$newArr[$val] = $val;
}
return $newArr;
return array_combine($arr, $arr);
}
/**

View File

@ -30,4 +30,20 @@ class ArrayLibTest extends SapphireTest {
)
);
}
function testValuekey() {
$this->assertEquals(
ArrayLib::valuekey(
array(
'testkey1' => 'testvalue1',
'testkey2' => 'testvalue2'
)
),
array(
'testvalue1' => 'testvalue1',
'testvalue2' => 'testvalue2'
)
);
}
}