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

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112572 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 03:24:32 +00:00
parent d99caf31f7
commit aa1553517c
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'
)
);
}
}