1

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

jacobappleton
  • 538
  • 8
  • 22

2 Answers2

1

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

Community
  • 1
  • 1
1

The complexity should be O(N).

It just loop it and use the callback to check the element.

You could find the implementation here.

xdazz
  • 158,678
  • 38
  • 247
  • 274