countDim() 공개 정적인 메소드

Counts the dimensions of an array. If $all is set to false (which is the default) it will only consider the dimension of the first element in the array.
public static countDim ( array $array, boolean $all = false, integer $count ) : integer
$array array Array to count dimensions on
$all boolean Set to true to count the dimension considering all elements in array
$count integer Start the dimension count at this number
리턴 integer The number of dimensions in $array
예제 #1
0
 /**
  * TestCountDim method
  *
  * @return void
  */
 public function testCountDim()
 {
     $data = ['one', '2', 'three'];
     $result = Utility::countDim($data);
     $this->assertEquals(1, $result);
     $data = ['1' => '1.1', '2', '3'];
     $result = Utility::countDim($data);
     $this->assertEquals(1, $result);
     $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => '3.1.1']];
     $result = Utility::countDim($data);
     $this->assertEquals(2, $result);
     $data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
     $result = Utility::countDim($data);
     $this->assertEquals(1, $result);
     $data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
     $result = Utility::countDim($data, true);
     $this->assertEquals(2, $result);
     $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
     $result = Utility::countDim($data);
     $this->assertEquals(2, $result);
     $data = ['1' => ['1.1' => '1.1.1'], '2', '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
     $result = Utility::countDim($data, true);
     $this->assertEquals(3, $result);
     $data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => '2.1.1.1']]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
     $result = Utility::countDim($data, true);
     $this->assertEquals(4, $result);
     $data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
     $result = Utility::countDim($data, true);
     $this->assertEquals(5, $result);
     $data = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
     $result = Utility::countDim($data, true);
     $this->assertEquals(5, $result);
     $set = ['1' => ['1.1' => '1.1.1'], ['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]], '3' => ['3.1' => ['3.1.1' => '3.1.1.1']]];
     $result = Utility::countDim($set, false, 0);
     $this->assertEquals(2, $result);
     $result = Utility::countDim($set, true);
     $this->assertEquals(5, $result);
     $data = ['one' => [null], ['null' => null], 'three' => [true, false, null]];
     $result = Utility::countDim($data, true);
     $this->assertEquals(2, $result);
 }