How to display the number of items in an array in PHP

admin

Administrator
Staff member
I'm using wordpress and based off the post I have an array of cards, each post will have a different number of cards in this array and I was wondering how I can show the number of cards in the array.

Code:
$class_cards[]=array('card_count'=>$card_count);

The total number of cards in this array will vary by post, so I want to be able to store the number of cards in a variable so I can echo it out later down the page.

Edit: Follow Up Question

I have a follow up to this question, I have a variable which is called
Code:
$card_count
which is stored in the array as you can see above. The card count will always be 1 or 2 saying that there is either one version of this card or two versions of this card. If there are two I would need to count that card twice in the overall number how can I do this with
Code:
count($class_cards)
?

For example lets say I have a total of 9 cards in that array. The count would turn out as 9, but in that array 6 out of those 9 cards have 2 as their card count, while 3 has 1 as their card count. So the total number of cards should be 15 instead of 9.