Jump to content


Photo

loopin through an array vs an object


  • Please log in to reply
1 reply to this topic

#1 emehrkay

emehrkay
  • Staff Alumni
  • Advanced Member
  • 1,214 posts

Posted 23 March 2006 - 03:07 PM

i have a for loop inside of a class that basically writes a table. i noticed that the way i was calling the index keys for the object will crap out if only one is returned, making it an array. how do i get around writing this bit of code twice? one with the index [$i] and one without?

$this->_data is the array/object
/*
            * Format dates
            */
            $start = $this->edit_date($this->_data[$i]->schedule_updates_start_date);
            $end   = $this->edit_date($this->_data[$i]->schedule_updates_end_date);
            $until = $this->edit_date($this->_data[$i]->schedule_updates_display_until);

* there are more than these three vals

i just want to say
if($count > 1){
//use index keys
}else{
//dont
}

#2 emehrkay

emehrkay
  • Staff Alumni
  • Advanced Member
  • 1,214 posts

Posted 24 March 2006 - 05:28 PM

*EDIT* i said it is an array if its only one, it really is an object if its only one, if more, its an array of those objects




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users