From aa1553517c663a7b438f1cad47062a12e6109872 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 15 Oct 2010 03:24:32 +0000 Subject: [PATCH] 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 --- core/ArrayLib.php | 6 +----- tests/ArrayLibTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/ArrayLib.php b/core/ArrayLib.php index 19df498cd..6195fe2b0 100755 --- a/core/ArrayLib.php +++ b/core/ArrayLib.php @@ -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); } /** diff --git a/tests/ArrayLibTest.php b/tests/ArrayLibTest.php index 4839e4e0e..f67765f7d 100644 --- a/tests/ArrayLibTest.php +++ b/tests/ArrayLibTest.php @@ -30,4 +30,20 @@ class ArrayLibTest extends SapphireTest { ) ); } + + function testValuekey() { + $this->assertEquals( + ArrayLib::valuekey( + array( + 'testkey1' => 'testvalue1', + 'testkey2' => 'testvalue2' + ) + ), + array( + 'testvalue1' => 'testvalue1', + 'testvalue2' => 'testvalue2' + ) + ); + } + } \ No newline at end of file