Welcome Guest, Not a member yet? Register   Sign In
unset value from object
#7

[eluser]Jeroen Brussich[/eluser]
I found a imho dirty solution, but I still would like somebody to have a look, point his finger and laugh at me and then provide me with the right code. :p
Code:
public function remove_doubles($candidates, $loaners)
    {
// 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
//iterate i
        $i = 0;
        foreach($candidates->result() as $candidate)
        {
            $needle    = $candidate->id;
            if(in_array($needle, $haystack))
            {
// DIRTY!!!
// hack into the object and force unset.
// manually reset num_rows
// do not user ->num_rows() after this, because it would return the number of rows of the initial object, not the hacked object.
                unset($candidates->result_object[0]);
                $candidates->num_rows = $candidates->num_rows -1;
            }
            $i++;
        }


// return hacked object or FALSE
        if($candidates->num_rows != 0) // do not use ->num_rows() but ->num_rows
        {
            sort($candidates->result_object);
            return $candidates;
        }
        return FALSE;
    }


Messages In This Thread
unset value from object - by El Forum - 11-24-2009, 04:09 AM
unset value from object - by El Forum - 11-24-2009, 04:12 AM
unset value from object - by El Forum - 11-24-2009, 05:24 AM
unset value from object - by El Forum - 11-24-2009, 06:06 AM
unset value from object - by El Forum - 11-24-2009, 06:22 AM
unset value from object - by El Forum - 11-24-2009, 06:38 AM
unset value from object - by El Forum - 11-24-2009, 07:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB