当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayList::filter方法代码示例

本文整理汇总了PHP中ArrayList::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::filter方法的具体用法?PHP ArrayList::filter怎么用?PHP ArrayList::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayList的用法示例。


在下文中一共展示了ArrayList::filter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveInto

 public function saveInto(\DataObjectInterface $record)
 {
     $v = $this->Value();
     $allItems = array();
     foreach ($this->children as $field) {
         $fieldname = $field->getName();
         if (strpos($fieldname, '__') > 0) {
             $bits = array_reverse(explode('__', $fieldname));
             if (count($bits) > 3) {
                 list($dataFieldName, $id, $classname) = $bits;
                 if (!isset($allItems["{$classname}-{$id}"])) {
                     $item = $this->records->filter(array('ClassName' => $classname, 'ID' => $id))->first();
                     $allItems["{$classname}-{$id}"] = $item;
                 }
                 $item = $allItems["{$classname}-{$id}"];
                 if ($item) {
                     if ($field) {
                         $field->setName($dataFieldName);
                         $field->saveInto($item);
                     }
                 }
             }
         }
     }
     foreach ($allItems as $item) {
         $item->write();
     }
     parent::saveInto($record);
 }
开发者ID:helpfulrobot,项目名称:nyeholt-silverstripe-multirecordeditor,代码行数:29,代码来源:MultiRecordEditingField.php

示例2: Menu

 public function Menu($level = 1)
 {
     if ($level == 1) {
         $root_elements = new ArrayList($this->get_root_elements());
         $result = $root_elements->filter(array("ShowInMenus" => 1));
     } else {
         $dataID = Director::get_current_page()->ID;
         $site_map = $this->get_site_map();
         if (isset($site_map[$dataID])) {
             $parent = $site_map[$dataID];
             $stack = array($parent);
             if ($parent) {
                 while ($parent = $parent->getParent()) {
                     array_unshift($stack, $parent);
                 }
             }
             if (isset($stack[$level - 2])) {
                 $elements = new ArrayList($stack[$level - 2]->getAllChildren());
                 $result = $elements->filter(array("ShowInMenus" => 1));
             }
         }
     }
     $visible = array();
     // Remove all entries the can not be viewed by the current user
     // We might need to create a show in menu permission
     if (isset($result)) {
         foreach ($result as $page) {
             if ($page->canView()) {
                 $visible[] = $page;
             }
         }
     }
     return new ArrayList($visible);
 }
开发者ID:helpfulrobot,项目名称:deviateltd-silverstripe-cacheable,代码行数:34,代码来源:CachedNavigation.php

示例3: testMultipleWithArrayFilterAdvanced

	/**
	 * $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43)));
	 */
	public function testMultipleWithArrayFilterAdvanced() {
		$list = new ArrayList(array(
			array('Name' => 'Steve', 'ID' => 1, 'Age'=>21),
			array('Name' => 'Steve', 'ID' => 2, 'Age'=>18),
			array('Name' => 'Clair', 'ID' => 2, 'Age'=>21),
			array('Name' => 'Clair', 'ID' => 2, 'Age'=>52),
			array('Name' => 'Steve', 'ID' => 3, 'Age'=>43)
		));
		
		$list->filter(array('Name'=>array('Steve','Clair'),'Age'=>array(21, 43)));
		
		$expected = array(
			array('Name' => 'Steve', 'ID' => 1, 'Age'=>21),
			array('Name' => 'Clair', 'ID' => 2, 'Age'=>21),
			array('Name' => 'Steve', 'ID' => 3, 'Age'=>43)
		);
		
		$this->assertEquals(3, $list->count());
		$this->assertEquals($expected, $list->toArray(), 'List should only contain Steve and Steve and Clair');
	}
开发者ID:redema,项目名称:sapphire,代码行数:23,代码来源:ArrayListTest.php


注:本文中的ArrayList::filter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。