Assuming that the callback function(s) that I am using have a time complexity of O(1), what is the running time of the array_filter function in PHP and is there somewhere I can find the implementation of the array_filter function?
Thanks
Assuming that the callback function(s) that I am using have a time complexity of O(1), what is the running time of the array_filter function in PHP and is there somewhere I can find the implementation of the array_filter function?
Thanks
The source of array_filter is in here, C-f for array_filter: https://github.com/php/php-src/blob/master/ext/standard/array.c
I found the answer (which states that array_filter is O(n), not entirely unobvious seeing it needs to iterate over every item in the list exactly once): List of Big-O for PHP functions
The complexity should be O(N)
.
It just loop it and use the callback to check the element.
You could find the implementation here.