Welcome Guest, Not a member yet? Register   Sign In
foreach on objects noob question
#1

[eluser]september28[/eluser]
Hi there,

Another noob question from me - I am having complete mind freeze as to how to loop an object.. here is my dilemma:
Code:
$this->db->select('links.ex1, links.ex2');
                $this->db->where('ex1',$row->exid);
                $this->db->or_where('ex2',$row->exid);
                $query2 = $this->db->get('links');
                if ($query2) {
                    $res2 = $query2->result();
                    foreach($res2 as $link) {
                        if($link->ex1 != $row->exid) {
                            $slug = $this->get_slug_from_explan_id($link->ex1);
                            $row->links[] = $slug;
                        } else {
                            $slug = $this->get_slug_from_explan_id($link->ex2);
                            $row->links[] = $slug;
                        }
                    }
                }

basically the $row->links variable is from a previous db query result now i want to create an object with multiple $slugs

the way i have it at the minute with $row->links[] = $slug means that the slug is nicely added to an array however i wasnted to keep consistent and have this as an object and then loop through the object in my view...

is there a way i can do the equivalent of [] with an object??

Cheers,

Dan
#2

[eluser]TheFuzzy0ne[/eluser]
No. That's what arrays are for. Smile There's nothing stopping you having an array of objects, though.

Everything in an object requires a name, so you'd have to assign like this@

Code:
$obj->some_var = TRUE;




Theme © iAndrew 2016 - Forum software by © MyBB