當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ArrayList::getIterator方法代碼示例

本文整理匯總了PHP中ArrayList::getIterator方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArrayList::getIterator方法的具體用法?PHP ArrayList::getIterator怎麽用?PHP ArrayList::getIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ArrayList的用法示例。


在下文中一共展示了ArrayList::getIterator方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testGetIterator

 public function testGetIterator()
 {
     // Remove the following lines when you implement this test.
     $it = $this->object->getIterator();
     $this->assertTrue($it instanceof \Iterator);
     $i = 0;
     $assert = false;
     foreach ($this->object as $val) {
         $assert = true;
         $this->assertTrue($val->toNative() == $i);
         $i++;
     }
     $this->assertTrue($assert);
     $it->next();
     $this->assertTrue($it->current()->toNative() === 1);
     $it->next();
     $it->next();
     $it->next();
     $it->remove();
 }
開發者ID:robo47,項目名稱:BlazeFramework,代碼行數:20,代碼來源:ArrayListTest.php

示例2: getTags

    /**
     * @return array
     */
    public function getTags()
    {
        if ($blog = $this->Blog()) {
            $escapedID = Convert::raw2sql($blog->ID);
            $sql = 'SELECT DISTINCT "BlogTag"."URLSegment","BlogTag"."Title",Count("BlogTagID") AS "TagCount"
				    from "BlogPost_Tags"
				    INNER JOIN "BlogPost"
				    ON "BlogPost"."ID" = "BlogPost_Tags"."BlogPostID"
				    INNER JOIN "BlogTag"
				    ON "BlogTag"."ID" = "BlogPost_Tags"."BlogTagID"
				    WHERE "BlogID" = ' . $escapedID . ' GROUP By  "BlogTag"."URLSegment","BlogTag"."Title"
				    ORDER BY "Title"';
            $records = DB::query($sql);
            $bloglink = $blog->Link();
            $maxTagCount = 0;
            // create DataObjects that can be used to render the tag cloud
            $tags = new ArrayList();
            foreach ($records as $record) {
                $tag = new DataObject();
                $tag->TagName = $record['Title'];
                $link = $bloglink . 'tag/' . $record['URLSegment'];
                $tag->Link = $link;
                if ($record['TagCount'] > $maxTagCount) {
                    $maxTagCount = $record['TagCount'];
                }
                $tag->TagCount = $record['TagCount'];
                $tags->push($tag);
            }
            // normalize the tag counts from 1 to 10
            if ($maxTagCount) {
                $tagfactor = 10 / $maxTagCount;
                foreach ($tags->getIterator() as $tag) {
                    $normalized = round($tagfactor * $tag->TagCount);
                    $tag->NormalizedTag = $normalized;
                }
            }
            return $tags;
        }
        return array();
    }
開發者ID:micmania1,項目名稱:silverstripe-blog,代碼行數:43,代碼來源:BlogTagsCloudWidget.php


注:本文中的ArrayList::getIterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。