I was wondering how computers do this.

The most logical way I can think is that they are iterating trough all elements of the list until they find one that matches the condition :)

For example if you call function_exists(), PHP should iterate trough all defined functions until it meets the one that matches the name you're looking for.

Is this true that this is the only way? If it is, it sounds like it's not very efficient :s

3 Answers 3


I'm a little confused by your question but here are a couple of ways that may speed up evaluating conditions:

If the list is sorted, then a binary search could be done that is more efficient than a brute force search through the list to find an element.

There can be short-circuit evaluations though can also speed up conditional evaluation.


Do some research on data structures, especially hash tables, which are frequently used for things like symbol tables. They use a function called a hash function to decide where to store the data, which has properties that make it very quick to retrieve at the expense of using some extra memory.


What you are talking about here is Search Algorithms.

The most common of these are:

1) Sequential Searches

2) Binary Search

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.