I have the following array that I want to count the element of “PaymentType” == paypal. I am using this method
$totalcount = count(array_filter((array) $data[0], 'paypal'));
but get the warning “‘paypal’, should be a valid callback”
Appreciate any response to help me get going in the right direction.
Array
(
[0] => Array
(
[TransactionDate] => 0000-00-00 00:00:00
[TotalAmount] => 0.00
[PayPalFee] => 2.48
[PayPalTransactionID] => 92
[PaymentType] => paypal
)
[1] => Array
(
[TransactionDate] => 0000-00-00 00:00:00
[TotalAmount] => 0.00
[PayPalFee] => 2.48
[PayPalTransactionID] => 3
[PaymentType] => paypal
)
[2] => Array
(
[TransactionDate] => 2011-05-16 11:15:02
[TotalAmount] => 75.00
[PayPalFee] => 2.48
[PayPalTransactionID] => 2
[PaymentType] => paypal
)
)
array_filter()is supposed to return a filtered array (and also needs a callback function to work, not a search value) – you don’t need to do that. Here’s a solution that really only counts the matches: