示例#1
0
 /**
  * Test that depth() returns an integer for the number of tiers in the array.
  */
 public function testDepth()
 {
     $data = $this->expanded;
     $data1 = $data;
     $data2 = $data;
     $data3 = $data;
     unset($data1['one']['two']['three']['four'], $data2['one']['two'], $data3['one']['two']['three']);
     $data4 = new stdClass();
     $data4->integer = 123;
     $data4->one = new stdClass();
     $data4->one->foo = 'bar';
     $this->assertEquals(0, Hash::depth(array()));
     $this->assertEquals(8, Hash::depth($data));
     $this->assertEquals(4, Hash::depth($data1));
     $this->assertEquals(2, Hash::depth($data2));
     $this->assertEquals(3, Hash::depth($data3));
     $this->assertEquals(2, Hash::depth($data4));
     $this->assertEquals(0, Hash::depth(array(), true));
     $this->assertEquals(8, Hash::depth($data, true));
     $this->assertEquals(4, Hash::depth($data1, true));
     $this->assertEquals(2, Hash::depth($data2, true));
     $this->assertEquals(3, Hash::depth($data3, true));
     $this->assertEquals(2, Hash::depth($data4, true));
     foreach (array(true, false, null, 123, 'foo') as $type) {
         try {
             $this->assertEquals(0, Hash::depth($type));
         } catch (Exception $e) {
             $this->assertTrue(true);
         }
     }
 }
示例#2
0
 function array_depth($set)
 {
     return Hash::depth($set);
 }