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


PHP array_filter函数代码示例

本文整理汇总了PHP中array_filter函数的典型用法代码示例。如果您正苦于以下问题:PHP array_filter函数的具体用法?PHP array_filter怎么用?PHP array_filter使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: start_el

 function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
 {
     $indent = $depth ? str_repeat("\t", $depth) : '';
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $classes[] = 'menu-item-' . $item->ID;
     $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth));
     /**
      * Change WP's default classes to match Foundation's required classes
      */
     $class_names = str_replace(array('menu-item-has-children'), array('has-submenu'), $class_names);
     // ==========================
     $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
     $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
     $id = $id ? ' id="' . esc_attr($id) . '"' : '';
     $output .= $indent . '<li' . $id . $class_names . '>';
     $atts = array();
     $atts['title'] = !empty($item->attr_title) ? $item->attr_title : '';
     $atts['target'] = !empty($item->target) ? $item->target : '';
     $atts['rel'] = !empty($item->xfn) ? $item->xfn : '';
     $atts['href'] = !empty($item->url) ? $item->url : '';
     $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
     $attributes = '';
     foreach ($atts as $attr => $value) {
         if (!empty($value)) {
             $value = 'href' === $attr ? esc_url($value) : esc_attr($value);
             $attributes .= ' ' . $attr . '="' . $value . '"';
         }
     }
     $item_output = $args->before;
     $item_output .= '<a' . $attributes . '>';
     $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
     $item_output .= '</a>';
     $item_output .= $args->after;
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
 }
开发者ID:andrewcroce,项目名称:TPL,代码行数:35,代码来源:offcanvas-walker.class.php

示例2: start_el

 function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
 {
     global $wp_query;
     $indent = $depth ? str_repeat("\t", $depth) : '';
     $class_names = $value = '';
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item));
     $class_names = ' class="' . esc_attr($class_names) . '"';
     $output .= $indent . '<li id="shopkeeper-menu-item-' . $item->ID . '"' . $value . $class_names . '>';
     $attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
     $attributes .= !empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
     $attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
     $attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
     $prepend = '';
     $append = '';
     //$description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
     if ($depth != 0) {
         $description = $append = $prepend = "";
     }
     $item_output = $args->before;
     $item_output .= '<a' . $attributes . '>';
     $item_output .= $args->link_before . $prepend . apply_filters('the_title', $item->title, $item->ID) . $append;
     //$item_output .= $description.$args->link_after;
     //$item_output .= ' '.$item->background_url.'</a>';
     $item_output .= '</a>';
     $item_output .= $args->after;
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
     apply_filters('walker_nav_menu_start_lvl', $item_output, $depth, $args->background_url = $item->background_url);
 }
开发者ID:hamaianhnhi,项目名称:shopkeeper148,代码行数:29,代码来源:custom_walker.php

示例3: _makeRequest

 /**
  * Sends a request to the REST API service and does initial processing
  * on the response.
  *
  * @param  string $op    Name of the operation for the request
  * @param  array  $query Query data for the request (optional)
  * @throws Zend_Service_Exception
  * @return DOMDocument Parsed XML response
  */
 protected function _makeRequest($op, $query = null)
 {
     if ($query != null) {
         $query = array_diff($query, array_filter($query, 'is_null'));
         $query = '?' . http_build_query($query);
     }
     $this->_http->setUri($this->_baseUri . $op . '.do' . $query);
     $response = $this->_http->request('GET');
     if ($response->isSuccessful()) {
         $doc = new DOMDocument();
         $doc->loadXML($response->getBody());
         $xpath = new DOMXPath($doc);
         $list = $xpath->query('/status/code');
         if ($list->length > 0) {
             $code = $list->item(0)->nodeValue;
             if ($code != 0) {
                 $list = $xpath->query('/status/message');
                 $message = $list->item(0)->nodeValue;
                 /**
                  * @see Zend_Service_Exception
                  */
                 require_once 'Zend/Service/Exception.php';
                 throw new Zend_Service_Exception($message, $code);
             }
         }
         return $doc;
     }
     /**
      * @see Zend_Service_Exception
      */
     require_once 'Zend/Service/Exception.php';
     throw new Zend_Service_Exception($response->getMessage(), $response->getStatus());
 }
开发者ID:basdog22,项目名称:Qool,代码行数:42,代码来源:Simpy.php

示例4: _insert

 function _insert()
 {
     $data['content'] = $_POST['content'];
     $data['add_file'] = $_POST['add_file'];
     $data['sender_id'] = get_user_id();
     $data['sender_name'] = get_user_name();
     $data['create_time'] = time();
     $model = D('Message');
     $arr_recever = array_filter(explode(";", $_POST['to']));
     foreach ($arr_recever as $val) {
         $tmp = explode("|", $val);
         $data['receiver_id'] = $tmp[1];
         $data['receiver_name'] = $tmp[0];
         $data['user_id'] = get_user_id();
         $list = $model->add($data);
         $data['user_id'] = $tmp[1];
         $list = $model->add($data);
     }
     //保存当前数据对象
     if ($list !== false) {
         //保存成功
         $this->assign('jumpUrl', get_return_url());
         $this->success('发送成功!');
     } else {
         //失败提示
         $this->error('发送失败!');
     }
 }
开发者ID:TipTimesPHP,项目名称:tyj_oa,代码行数:28,代码来源:MessageAction.class.php

示例5: request

 public function request($type, $url, array $params = array(), array $properties = array())
 {
     $params = array_filter($params);
     $ch = curl_init();
     switch (strtolower($type)) {
         case 'post':
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
             break;
         case 'get':
             $url = $this->buildQueryString($url, $params);
             break;
         case 'delete':
             $url = $this->buildQueryString($url, $params);
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
             break;
         case 'update':
         case 'put':
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
             break;
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_URL, $url);
     foreach ($properties as $propertyKey => $propertyValue) {
         curl_setopt($ch, $propertyKey, $propertyValue);
     }
     $response = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     return new Response($info, $response);
 }
开发者ID:replay4me,项目名称:samba,代码行数:32,代码来源:APIBase.php

示例6: newRequest

 /**
  * Checks the queue for matches to this request.
  * If a group can be formed, returns an array with the sessions that will form this group.
  * Otherwise, returns FALSE.
  *
  * @param GroupRequest $request
  * @return array<Session> if a group can be formed, FALSE otherwise
  */
 public function newRequest(GroupRequest $request)
 {
     // filter all requests that match this one
     $matches = array_filter($this->requests, function ($potential_match) use($request) {
         return !$potential_match->expired() && $request->match($potential_match);
     });
     if (count($matches) + 1 >= $request->size()) {
         // we have enough people to form a group!
         // get as many of the matches as we need for the group
         $selected_requests = array_slice($matches, 0, $request->size() - 1);
         // remove the fulfilled grouprequests from the queue
         $this->removeRequests($selected_requests);
         // get the sessions that will make up this group
         $sessions = array_map(function ($selected_request) {
             return $selected_request->session;
         }, $selected_requests);
         $sessions[] = $request->session;
         // don't forget the new request
         return $sessions;
     } else {
         // not enough requests matching this one
         // add this request to the queue
         $this->addRequest($request);
         return FALSE;
     }
 }
开发者ID:nmalkin,项目名称:basset,代码行数:34,代码来源:grouprequestqueue.php

示例7: addCommandsFromClass

 public function addCommandsFromClass($className, $passThrough = null)
 {
     $roboTasks = new $className();
     $commandNames = array_filter(get_class_methods($className), function ($m) {
         return !in_array($m, ['__construct']);
     });
     foreach ($commandNames as $commandName) {
         $command = $this->createCommand(new TaskInfo($className, $commandName));
         $command->setCode(function (InputInterface $input) use($roboTasks, $commandName, $passThrough) {
             // get passthru args
             $args = $input->getArguments();
             array_shift($args);
             if ($passThrough) {
                 $args[key(array_slice($args, -1, 1, TRUE))] = $passThrough;
             }
             $args[] = $input->getOptions();
             $res = call_user_func_array([$roboTasks, $commandName], $args);
             if (is_int($res)) {
                 exit($res);
             }
             if (is_bool($res)) {
                 exit($res ? 0 : 1);
             }
             if ($res instanceof Result) {
                 exit($res->getExitCode());
             }
         });
         $this->add($command);
     }
 }
开发者ID:stefanhuber,项目名称:Robo,代码行数:30,代码来源:Application.php

示例8: update

 /**
  * Updates a team resource
  * 
  * @param \Badgeville\Api\Cairo\Sites\Teams $obj
  * @return \Badgeville\Api\Cairo\Sites\Teams
  */
 public function update($obj = null)
 {
     $useSelf = false;
     if ($obj instanceof $this) {
         $objData = $obj->toArray();
     } else {
         $useSelf = true;
         $objData = $this->data;
     }
     $properties = ['display_name' => FILTER_SANITIZE_STRING, 'name' => FILTER_SANITIZE_STRING, 'active' => ['filter' => FILTER_VALIDATE_BOOLEAN, 'flags' => FILTER_NULL_ON_FAILURE], 'display_priority' => FILTER_SANITIZE_NUMBER_INT];
     // need to remove null values
     $data = array_filter($objData, function ($value) {
         return is_null($value) ? false : true;
     });
     // clean params up
     $data = filter_var_array($data, $properties, false);
     $params = ['do' => 'update', 'data' => json_encode($data, JSON_UNESCAPED_SLASHES)];
     $response = $this->getSite()->getRequest($this->uriBuilder() . '/' . $this->id, $params);
     if ($useSelf) {
         return $this->setData($response[$this->getResourceName()][0]);
     }
     $player = clone $this;
     $player->setData();
     return $player;
 }
开发者ID:joeyrivera,项目名称:badgeville-php,代码行数:31,代码来源:Teams.php

示例9: processRequest

 public function processRequest()
 {
     // No CSRF for SendGrid.
     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
     $request = $this->getRequest();
     $user = $request->getUser();
     $raw_headers = $request->getStr('headers');
     $raw_headers = explode("\n", rtrim($raw_headers));
     $raw_dict = array();
     foreach (array_filter($raw_headers) as $header) {
         list($name, $value) = explode(':', $header, 2);
         $raw_dict[$name] = ltrim($value);
     }
     $headers = array('to' => $request->getStr('to'), 'from' => $request->getStr('from'), 'subject' => $request->getStr('subject')) + $raw_dict;
     $received = new PhabricatorMetaMTAReceivedMail();
     $received->setHeaders($headers);
     $received->setBodies(array('text' => $request->getStr('text'), 'html' => $request->getStr('from')));
     $file_phids = array();
     foreach ($_FILES as $file_raw) {
         try {
             $file = PhabricatorFile::newFromPHPUpload($file_raw, array('authorPHID' => $user->getPHID()));
             $file_phids[] = $file->getPHID();
         } catch (Exception $ex) {
             phlog($ex);
         }
     }
     $received->setAttachments($file_phids);
     $received->save();
     $received->processReceivedMail();
     $response = new AphrontWebpageResponse();
     $response->setContent("Got it! Thanks, SendGrid!\n");
     return $response;
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:33,代码来源:PhabricatorMetaMTASendGridReceiveController.php

示例10: getFilteredEventsWithObserversCount

 protected function getFilteredEventsWithObserversCount()
 {
     $eventsWithObservers = array_filter($this->getFilteredEvents(), function ($item) {
         return count($item['observers']) > 0;
     });
     return count($eventsWithObservers);
 }
开发者ID:akits,项目名称:magento_zh_TW,代码行数:7,代码来源:Events.php

示例11: addressFromIP

 protected function addressFromIP($ip)
 {
     $geocoder = AddressGeocoding::get_geocoder();
     $geodata = array();
     try {
         if ($ip) {
             $geodata = $geocoder->geocode($ip)->toArray();
         }
     } catch (Exception $e) {
         SS_Log::log($e, SS_Log::ERR);
     }
     $geodata = array_filter($geodata);
     $datamap = array('Country' => 'countryCode', 'County' => 'county', 'State' => 'region', 'PostalCode' => 'zipcode', 'Latitude' => 'latitude', 'Longitude' => 'longitude');
     $mappeddata = array();
     foreach ($datamap as $addressfield => $geofield) {
         if (is_array($geofield)) {
             if ($data = implode(" ", array_intersect_key($geodata, array_combine($geofield, $geofield)))) {
                 $mappeddata[$addressfield] = $data;
             }
         } elseif (isset($geodata[$geofield])) {
             $mappeddata[$addressfield] = $geodata[$geofield];
         }
     }
     return $mappeddata;
 }
开发者ID:burnbright,项目名称:silverstripe-shop-geocoding,代码行数:25,代码来源:GeocodedUserInfo.php

示例12: index

 /**
  * @return Response
  */
 public function index(Container $p_dependencies)
 {
     $request = RequestWrapper::$request;
     $session = SessionFactory::getSession();
     $options = ['blaze' => (bool) $request->get('blaze'), 'deflect' => (bool) $request->get('deflect'), 'duel' => (bool) $request->get('duel'), 'evade' => (bool) $request->get('evasion'), 'attack' => !(bool) $request->get('duel')];
     $target = Player::find($request->get('target'));
     $attacker = Player::find($session->get('player_id'));
     $skillListObj = new Skill();
     $ignores_stealth = false;
     $required_turns = 0;
     foreach (array_filter($options) as $type => $value) {
         $ignores_stealth = $ignores_stealth || $skillListObj->getIgnoreStealth($type);
         $required_turns += $skillListObj->getTurnCost($type);
     }
     $params = ['required_turns' => $required_turns, 'ignores_stealth' => $ignores_stealth];
     try {
         $rules = new AttackLegal($attacker, $target, $params);
         $attack_is_legal = $rules->check();
         $error = $rules->getError();
     } catch (\InvalidArgumentException $e) {
         $attack_is_legal = false;
         $error = 'Could not determine valid target';
     }
     if (!$attack_is_legal) {
         // Take away at least one turn even on attacks that fail.
         $attacker->turns = $attacker->turns - 1;
         $attacker->save();
         $parts = ['target' => $target, 'attacker' => $attacker, 'error' => $error];
         return new StreamedViewResponse('Battle Status', 'attack_mod.tpl', $parts, ['quickstat' => 'player']);
     } else {
         return $this->combat($attacker, $target, $required_turns, $options);
     }
 }
开发者ID:BitLucid,项目名称:ninjawars,代码行数:36,代码来源:AttackController.php

示例13: process

 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $allowed_tags = array_filter($this->settings['restrictions']['allowed'], function ($value) {
         return is_array($value) || (bool) $value !== FALSE;
     });
     return new FilterProcessResult(Xss::filter($text, array_keys($allowed_tags)));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:FilterTestRestrictTagsAndAttributes.php

示例14: start_el

 function start_el(&$output, $item, $depth = 0, $args = array(), $current_object_id = 0)
 {
     global $wp_query;
     $indent = $depth ? str_repeat("\t", $depth) : '';
     $class_names = $value = '';
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $classes[] = 'menu-item-' . $item->ID;
     if ($args->has_children) {
         $classes[] = 'dropdown';
     }
     $icon_html = '';
     if (isset($item->custom_icon) && !empty($item->custom_icon)) {
         $icon_html = '<i class="' . $item->custom_icon . '"></i><span>&nbsp;&nbsp;</span>';
     }
     $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
     $class_names = ' class="' . esc_attr($class_names) . '"';
     $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args);
     $id = strlen($id) ? ' id="' . esc_attr($id) . '"' : '';
     $output .= $indent . '<li' . $id . $value . $class_names . '>';
     $attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
     $attributes .= !empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
     $attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
     $attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
     $item_output = $args->before;
     $item_output .= '<a' . $attributes . '>';
     $item_output .= $args->link_before . $icon_html . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
     $item_output .= '</a>';
     $item_output .= $args->after;
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
 }
开发者ID:alispx,项目名称:calibrefx,代码行数:30,代码来源:Walker_nav_menu.php

示例15: parse

 public function parse(\Twig_Token $token)
 {
     $inputs = array();
     $attrs = array('filters' => array());
     $stream = $this->parser->getStream();
     while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
         if ($stream->test(\Twig_Token::STRING_TYPE)) {
             $inputs[] = $stream->next()->getValue();
         } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'filter')) {
             $stream->next();
             $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
             $attrs['filters'] = array_merge($attrs['filters'], array_filter(array_map('trim', explode(',', $stream->expect(\Twig_Token::STRING_TYPE)->getValue()))));
         } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'output')) {
             $stream->next();
             $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
             $attributes['output'] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
         } else {
             $token = $stream->getCurrent();
             throw new \Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', \Twig_Token::typeToEnglish($token->getType(), $token->getLine()), $token->getValue()), $token->getLine());
         }
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $content = $this->parser->subparse(array($this, 'testEndTag'), true);
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $this->manager->load($inputs, $attrs, $this->getTag());
     $params['assets'] = $this->manager->getAssetsPath();
     return new TlAssetsNode(array('content' => $content), $params, $token->getLine(), $this->getTag());
 }
开发者ID:electrotiti,项目名称:tlassets-bundle,代码行数:28,代码来源:TlAssetsTokenParser.php


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