Google Groups Home
Help | Sign in
Find by Like (Continued)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Joel  
View profile
 More options Mar 9 2006, 10:50 am
From: "Joel" <joel...@gmail.com>
Date: Thu, 09 Mar 2006 15:50:44 -0000
Local: Thurs, Mar 9 2006 10:50 am
Subject: Find by Like (Continued)
This is an improvement to the "Find By Like" function I proposed
earlier
(http://groups.google.com/group/Php-Object-Generator/browse_frm/thread...)
submitted by Vitek

 function filterList($objectList, $attributeToCompare, $value) {
               $filteredList = array();
               foreach ($objectList as $object){
                       if (is_array($attributeToCompare)) {
                                       for ($i = 0; $i <
sizeof($attributeToCompare); $i++) {
                                       if
(strpos($object->{$attributeToCompare[$i]}, $value) !== false){
                                               $filteredList[] =
$object;
                                               break;
                                   }
                                       }
                               } else {
                               if
(strpos($object->{$attributeToCompare}, $value) !== false){
                                       $filteredList[] = $object;
                           }
                       }
               }
               return $filteredList;
       }

----------------------
Now as $attributeToCompare it accepts array and I also added a check
!== false, because strpos can return 0, if the search is just on the
beginning - and the whole if fails even if it shouldn't

Thanks Vitek


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google