Same question here but I find its answer a bit misleading. My answer would be YES. You need to loop through the whole array to find a specific element and the worst case complexity is O(n). Unless:
- you use associative array and ask the element by its key. Then the search takes constant time O(1).
- you ask element by its index (you know where the element is and you go there directly). Then the search takes constant time O(1).
As I sometimes lock myself out from Facebook I have no idea if any of my friends is having a birthday any time soon. I also already have difficulty remembering ages and birthdays of all my relatives (especially new ones). Before solving my personal CRM needs with Monica I decided to build something myself.
Today I worked on building a small web app using sqlite and php to save/edit/delete birthdays of my friends and family, calculate ages etc.
Most difficult was to figure out how to sort recurring (yearly) events starting from “next upcoming” with single SQL query. But I think I figured it out by using one SQL query followed small php loop (which has worst case complexity of O(n)) to find the place to split an array 🙂
SELECT id, firstname, lastname, birthday,
(current_date - birthday - 1) as age,
substr(birthday, 9, 100) as day,
substr(birthday, 6, 2) as month
ORDER BY month, day;
Hopefully I can get it ready enough at some point for sharing on Github. Something cool for the end: OpenAI has trained a model that can create new images – you just describe them in English. Mindblowing.