I’ve around 80 instances of this class called Items and would like to efficiently search the objects by their ID or NAME.
<?php
class Item
{
public $id;
public $name;
//methods
}
?>
I’m using PHP5.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming no duplicate names or IDs:
If you have duplicates (of names; I imagine there are no duplicate IDs by definition) then you need to work out how to handle that. You could store all the duplicates under one key (so the value becomes an array of matches).
Or do you mean a more sophisticated search? If so, a simple variant might be to break up the item name into words and/or phrases and then index them accordingly into an array.