예제 #1
0
파일: ArrayUtilTest.php 프로젝트: jyxo/php
 /**
  * Tests the keymap() method.
  */
 public function testKeymap()
 {
     $source = [];
     foreach (range(ord('a'), ord('z')) as $value) {
         $source[] = chr($value);
     }
     $traversable = new \ArrayIterator($source);
     $closure = function ($value) {
         return chr(ord('z') + ord('a') - ord($value));
     };
     $mapped = ArrayUtil::keymap($traversable, $closure);
     $this->assertSame(array_combine(array_reverse($source), $source), $mapped);
     $mapped = ArrayUtil::keymap($traversable, $closure, $closure);
     $this->assertSame(array_reverse(array_combine($source, $source)), $mapped);
 }