2

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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.