Esempio n. 1
0
 public function testIGroup()
 {
     $apple = ['name' => 'Apple', 'type' => 'fruit', 'colour' => 'green', 'group' => 'food'];
     $bear = ['name' => 'Bear', 'type' => 'animal', 'colour' => 'brown', 'group' => 'creature'];
     $carrot = ['name' => 'Carrot', 'type' => 'vegetable', 'colour' => 'brown', 'group' => 'food'];
     $list = ['a' => $apple, 'b' => $bear, 'c' => $carrot];
     $expect = ['fruit' => ['a' => $apple], 'animal' => ['b' => $bear], 'vegetable' => ['c' => $carrot]];
     $this->assertEquals($expect, Arrays::igroup($list, 'type'));
     $expect = ['food' => ['fruit' => ['a' => $apple], 'vegetable' => ['c' => $carrot]], 'creature' => ['animal' => ['b' => $bear]]];
     $this->assertEquals($expect, Arrays::igroup($list, 'group', 'type'));
     $expect = ['food' => ['a' => $apple, 'c' => $carrot], 'creature' => ['b' => $bear]];
     $this->assertEquals($expect, Arrays::igroup($list, 'group'));
 }