Count number of array elements inside multidimensional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Count number of array elements inside multidimensional array

Post 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.
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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]);
Post Reply