示例#1
0
 /**
  * Test that each() runs the callback on every value.
  */
 public function testEach()
 {
     $data = array('integer' => 123, 'number' => '456', 'foo' => 'bar', 'string' => 'test', 'boolean' => true, 'array' => array(525, 'boo'));
     $this->assertEquals(array('integer' => 246, 'number' => 912, 'foo' => 'barwtf', 'string' => 'testwtf', 'boolean' => true, 'array' => array(1050, 'boowtf')), Hash::each($data, function ($value, $key) {
         if (is_numeric($value)) {
             return $value * 2;
         } elseif (is_string($value)) {
             return $value . 'wtf';
         }
         return $value;
     }));
     $this->assertEquals(array('integer' => 246, 'number' => 912, 'foo' => 'barwtf', 'string' => 'testwtf', 'boolean' => true, 'array' => array(525, 'boo')), Hash::each($data, function ($value, $key) {
         if (is_numeric($value)) {
             return $value * 2;
         } elseif (is_string($value)) {
             return $value . 'wtf';
         }
         return $value;
     }, false));
 }
示例#2
0
 function array_each(array $set, Closure $callback, $recursive = true)
 {
     return Hash::each($set, $callback, $recursive);
 }