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
takes a callback as second argument, as described in the documentation: php.net/manual/en/function.array-filter.php. There you will also find examples on how to usearray_filter
. – Felix Kling Jan 3 at 14:44