Page 1 of 1

Count number of array elements inside multidimensional array

Posted: Thu May 17, 2007 5:10 am
by facets
Hi All,

As the subject suggests how do I count the number of inner arrays in a multiD array?
Here's the 2 arrays I wish to run a conditional statement over. I can see the count there I am unsure on how to access it.

If sub-array has 2 elements do this else if has 3 elements do this.

Code: Select all

array(5) {
  [0]=>
  array(2) {
    [0]=>
    int(37)
    [1]=>
    string(7) "21406.8"
  }
}

Code: Select all

array(6) {
  [0]=>
  array(3) {
    ["client_id"]=>
    string(2) "97"
    ["totalThisQuater"]=>
    string(6) "780.22"
    ["totalLastQuater"]=>
    string(6) "487.83"
  }
}
Any pointers or suggestions?

tia, Will.

Posted: Thu May 17, 2007 5:33 am
by facets
Apologies for answering my own question.
The following seems to do the job. Unless anyone has a better solution.

Code: Select all

$newCount = count($toXML[0]);