当前位置: 首页>>代码示例>>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;未经允许,请勿转载。