Hi,

I have a resultset which is an array with either 1 or 2 or 3 or 4 ... dimentions. How can I find out how many dimentions are returned?

Thanks

Member Avatar for diafol
function adc($arrayVariable, $counter = 0) {
	if(is_array($arrayVariable)) {
		return adc(current($arrayVariable), $counter + 1);
	} else {
		return $counter;
	}
}

This isn't my code - can't remember where I got it - from some forum last summer - think it was Big Resource.

So:

$no_dimensions = adc($mybigarray);

ok i understand your problem.

Here is solution

function getArrCount ($arr, $depth=1) {
      if (!is_array($arr) || !$depth) return 0;
        
     $res=count($arr);
        
      foreach ($arr as $in_ar)
         $res+=getArrCount($in_ar, $depth-1);
     
      return $res;
  }

example:

$shop = array(array(array("rose", 1.25, 15),
                    array("daisy", 0.75, 25),
                    array("orchid", 1.15, 7) 
                   ),
              array(array("rose", 1.25, 15),
                    array("daisy", 0.75, 25),
                    array("orchid", 1.15, 7) 
                   ),
              array(array("rose", 1.25, 15),
                    array("daisy", 0.75, 25),
                    array("orchid", 1.15, 7) 
                   )
             );
// call the function

echo getArrCount ($shop);

I hope this will help you.

Solved. Thanks guys

function adc($arrayVariable, $counter = 0) {	
if(is_array($arrayVariable)) {		
return adc(current($arrayVariable), $counter + 1);	
} else {		
return $counter;	}
}
Member Avatar for diafol

Possible to mark it solved? thnx.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.