[eluser]Jeroen Brussich[/eluser]
How do I remove a certain value from an object?
I'm writing a library program for my highschool. I'm currently working on the part where you can assign a student to a book. You search for a student (candidates) and the view returns only those students (candidates) that match your search. I'm trying to filter out those matches that already have the book in their possession (loaners).
I thought that matching user_ids would be a good way to do this. Pass the loaners (those who already have the book in their possession) and the candidates (those who match the search) to a method. If the user_ids match, you got a double and you remove that double from the object candidates.
Then you return the candidates and you display them.
Everything seems to work, right up to the point where I try to delete the candidate from the object candidates. It just doesn't do anything...
So: How do I remove a certain value from an object?
Code:
public function remove_doubles($loaners, $candidates)
{
// build an array with the user_ids
$haystack = array();
foreach($loaners->result() as $loaner)
{
$haystack[] = $loaner->id;
}
//look if the user_id from the candidate is in the already_loaned_haystack
foreach($candidates->result() as $candidate)
{
$needle = $candidate->id;
if(in_array($needle, $haystack))
{
//If so, remove the candidate from the object.
unset($candidate) // FAILS!
}
}
}