I have quite a strange array:
Array
(
[title] => title
[weight] => 0
[0] => Text1
[1] => Text2
[additional] => Info
}
How do I count array elements which keys are numeric (only)?
$data = array(
'title' => 'title',
'weight' => 0,
0 => 'Text1',
1 => 'Text2',
'additional' => 'Info'
);
$keyCount = count(
array_filter(
array_keys($data),
'is_numeric'
)
);
var_dump($keyCount);
EDIT
And from PHP version 5.6.0, you can use
$keyCount = count(
array_filter($data, 'is_numeric', ARRAY_FILTER_USE_KEY)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With