function _pick($object, $keys)
{
    return Underscore::pick($object, $keys);
}
示例#2
0
 /**
  * @tags objects
  */
 public function testPick()
 {
     // it should be able to extract certain keys from a list and preserve the general type
     $this->array(_::pick(['a' => 1, 'b' => 2, 'c' => 3], ['b', 'c']))->isEqualTo(['b' => 2, 'c' => 3]);
     // 2nd form
     $this->array(_::pick(['a' => 1, 'b' => 2, 'c' => 3], 'b', 'c'))->isEqualTo(['b' => 2, 'c' => 3]);
     // it shoud ignore keys that are not part of the list/object
     $object = new \stdClass();
     $object->a = 1;
     $this->object(_::pick($object, 'a', 'b', 'c'))->isEqualTo((object) ['a' => 1]);
     // it should preserve keys order of picked keys
     $this->array(_::pick(['a' => 1, 'b' => 2, 'c' => 3], 'c', 'b', 'a'))->keys->isEqualTo(['c', 'b', 'a']);
 }