PHP並沒有真正的多維度陣列,只是Array中的元素可以是Array。
我想你恐怕需要寫一個函數或是類別,用遞迴的方式遍歷陣列元素,來計算出可能的維度。
例如:
<pre class="c" name="code">
<?php
class ArrayDim {
private $_array;
private $count=0;
public $dimension=1;
function __construct($a) {
$this->_array = $a;
}
function check() {
$this->check_rec($this->_array);
return $this->dimension;
}
private function check_rec($_a=array()) {
$this->count++;
if($this->count>$this->dimension)
$this->dimension = $this->count;
foreach($_a as $v) {
if(is_array($v)) {
$this->check_rec($v);
}
}
$this->count--;
}
}
$a = array(array(1,3,5), 3, array(2,4), 4, array(1,array(1,6,4,array(2,4)),8,9));
$b = new ArrayDim($a);
print_r($a);
echo "<br>dimension: ".$b->check();
?>