function get_index_in_gallery() { $all_photos = Photos::FindByGalleryId($this->gallery_id); $count = 0; foreach ($all_photos as $photo) { $count += 1; if ($photo->id == $this->id) { return $count; } } return 0; }