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


PHP array_walk_recursive函数代码示例

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


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

示例1: execute

 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $doctrine = $this->getContainer()->get('doctrine');
     $em = $doctrine->getManager();
     $name = $input->getArgument('name');
     $system = $input->getArgument('system');
     /* @var RepositoryInterface $roleRepository */
     $repository = $this->getContainer()->get('sulu.repository.role');
     $role = $repository->findOneByName($name);
     if ($role) {
         $output->writeln(sprintf('<error>Role "%s" already exists.</error>', $name));
         return 1;
     }
     /** @var RoleInterface $role */
     $role = $repository->createNew();
     $role->setName($name);
     $role->setSystem($system);
     $pool = $this->getContainer()->get('sulu_admin.admin_pool');
     $securityContexts = $pool->getSecurityContexts();
     // flatten contexts
     $securityContextsFlat = [];
     array_walk_recursive($securityContexts['Sulu'], function ($value) use(&$securityContextsFlat) {
         $securityContextsFlat[] = $value;
     });
     foreach ($securityContextsFlat as $securityContext) {
         $permission = new Permission();
         $permission->setRole($role);
         $permission->setContext($securityContext);
         $permission->setPermissions(127);
         $role->addPermission($permission);
     }
     $em->persist($role);
     $em->flush();
     $output->writeln(sprintf('Created role "<comment>%s</comment>" in system "<comment>%s</comment>".', $role->getName(), $role->getSystem()));
 }
开发者ID:Silwereth,项目名称:sulu,代码行数:38,代码来源:CreateRoleCommand.php

示例2: search_articles

 public function search_articles($q, $topic_ids = null, $page = 1, $limit = 20, $is_recommend = false)
 {
     if ($topic_ids) {
         $topic_ids = explode(',', $topic_ids);
         array_walk_recursive($topic_ids, 'intval_string');
         $where[] = '`id` IN (SELECT `item_id` FROM ' . $this->get_table('topic_relation') . ' WHERE topic_id IN(' . implode(',', $topic_ids) . ') AND `type` = "article")';
     }
     if ($is_recommend) {
         $where[] = '(`is_recommend` = "1" OR `chapter_id` IS NOT NULL)';
     }
     if ($where) {
         $where = implode(' AND ', $where);
     }
     $search_hash = $this->get_search_hash('article', 'title', $q, $where);
     if (!($result = $this->fetch_cache($search_hash))) {
         if ($result = $this->query_all($this->bulid_query('article', 'title', $q, $where), $this->max_results)) {
             $result = aasort($result, 'score', 'DESC');
         } else {
             return false;
         }
         $this->save_cache($search_hash, $result);
     }
     if (!$page) {
         $slice_offset = 0;
     } else {
         $slice_offset = ($page - 1) * $limit;
     }
     return array_slice($result, $slice_offset, $limit);
 }
开发者ID:egogg,项目名称:wecenter-dev,代码行数:29,代码来源:fulltext.php

示例3: array_map_recursive

 public static function array_map_recursive($func, $arr)
 {
     array_walk_recursive($arr, function (&$w) use($func) {
         $w = $func($w);
     });
     return $arr;
 }
开发者ID:hzhou9,项目名称:coupon_deal,代码行数:7,代码来源:utils.php

示例4: motopressCEJsonEncode

function motopressCEJsonEncode($array)
{
    //convmap since 0x80 char codes so it takes all multibyte codes (above ASCII 127). So such characters are being "hidden" from normal json_encoding
    $options = array('convmap' => array(0x80, 0xffff, 0, 0xffff), 'encoding' => 'UTF-8');
    array_walk_recursive($array, 'motopressCEMbEncodeNumericentity', $options);
    return mb_decode_numericentity(json_encode($array), $options['convmap'], $options['encoding']);
}
开发者ID:umang11,项目名称:glotech,代码行数:7,代码来源:functions.php

示例5: render

 /**
  * Renders a template.
  *
  * @param mixed $name       A template name or a TemplateReferenceInterface instance
  * @param array $parameters An array of parameters to pass to the template
  *
  * @return string The evaluated template as a string
  *
  * @throws \RuntimeException if the template cannot be rendered
  *
  * @api
  */
 public function render($name, array $parameters = array())
 {
     $objectConverter = $this->objectConverter;
     $legacyVars = array();
     foreach ($parameters as $varName => $param) {
         // If $param is an array, we recursively convert all objects contained in it (if any).
         // Scalar parameters are passed as is
         if (is_array($param)) {
             array_walk_recursive($param, function (&$element) use($objectConverter) {
                 if (is_object($element) && !$element instanceof LegacyCompatible) {
                     $element = $objectConverter->convert($element);
                 }
             });
             $legacyVars[$varName] = $param;
         } else {
             if (!is_object($param) || $param instanceof LegacyCompatible) {
                 $legacyVars[$varName] = $param;
             } else {
                 $objectConverter->register($param, $varName);
             }
         }
     }
     $legacyVars += $objectConverter->convertAll();
     return $this->getLegacyKernel()->runCallback(function () use($name, $legacyVars) {
         $tpl = eZTemplate::factory();
         foreach ($legacyVars as $varName => $value) {
             $tpl->setVariable($varName, $value);
         }
         return ezpEvent::getInstance()->filter('response/output', $tpl->fetch($name));
     }, false);
 }
开发者ID:masev,项目名称:ezpublish-kernel,代码行数:43,代码来源:LegacyEngine.php

示例6: parseBlueprint

 /**
  * @param $blueprint
  *
  * @return array
  * @throws \InvalidArgumentException
  */
 protected function parseBlueprint($blueprint)
 {
     $callback = function (&$value) {
         if (is_string($value)) {
             $value = str_replace(':current', '*', $value);
         }
         if ($value[0] === ':') {
             # structure
             $structure = $this->getStructure($value);
             $value = $this->parseBlueprint($structure);
             return;
         }
         if (strpos($value, '|') === false) {
             return;
         }
         $parts = preg_split('/\\s?\\|\\s?/', $value);
         $selector = array_shift($parts);
         $value = ApistConf::select($selector);
         foreach ($parts as $part) {
             $this->addCallbackToFilter($value, $part);
         }
     };
     if (!is_array($blueprint)) {
         $callback($blueprint);
     } else {
         array_walk_recursive($blueprint, $callback);
     }
     return $blueprint;
 }
开发者ID:noxify,项目名称:apist,代码行数:35,代码来源:BlueprintConfigParser.php

示例7: arrayMapRecursive

 /**
  * array_map_recursive, which is missing from PHP, with the same signature
  *
  * @param callable $func
  * @param array    $arr
  *
  * @return array
  */
 public static function arrayMapRecursive(callable $func, array $arr)
 {
     array_walk_recursive($arr, function (&$v) use($func) {
         $v = $func($v);
     });
     return $arr;
 }
开发者ID:fhteam,项目名称:laravel-amqp,代码行数:15,代码来源:ArrayUtil.php

示例8: get_feature_by_id

 public function get_feature_by_id($feature_id)
 {
     if (!$feature_id) {
         return false;
     }
     if (is_array($feature_id)) {
         $feature_ids = $feature_id;
         if (sizeof($feature_ids) == 0) {
             return false;
         }
     } else {
         $feature_ids[] = $feature_id;
     }
     array_walk_recursive($feature_ids, 'intval_string');
     if ($features = $this->fetch_all('feature', 'id IN (' . implode(',', $feature_ids) . ')')) {
         foreach ($features as $key => $val) {
             if (!$val['url_token']) {
                 $features[$key]['url_token'] = $val['id'];
             }
             $data[$val['id']] = $features[$key];
         }
     }
     if (is_array($feature_id)) {
         return $data;
     } else {
         return $data[$feature_id];
     }
 }
开发者ID:Vizards,项目名称:HeavenSpree,代码行数:28,代码来源:feature.php

示例9: __get

 /**
  * Magic function which handles the properties accessibility.
  * @param string $propertyName The property name.
  */
 public function __get($propertyName)
 {
     switch ($propertyName) {
         default:
             $value = null;
             // Get - Post - Cookie.
             if (array_key_exists($propertyName, $_GET)) {
                 $value = $_GET[$propertyName];
             } else {
                 if (array_key_exists($propertyName, $_POST)) {
                     $value = $_POST[$propertyName];
                 } else {
                     if (array_key_exists($propertyName, $_COOKIE)) {
                         $value = $_COOKIE[$propertyName];
                     }
                 }
             }
             // Case of an array.
             if (is_array($value)) {
                 array_walk_recursive($value, array($this, 'cleanValue'));
                 return $value;
             }
             // Else.
             return $this->cleanValue($value);
     }
 }
开发者ID:Gnucki,项目名称:DaFramework,代码行数:30,代码来源:ContextHandler.php

示例10: shutdown

 /**
  * Shutdown event
  *
  * @param \Cake\Event\Event $event The event
  * @return void
  */
 public function shutdown(Event $event)
 {
     $controller = $event->subject();
     $errors = [];
     array_walk_recursive($controller->viewVars, function (&$item) {
         // Execute queries so we can show the results in the toolbar.
         if ($item instanceof Query) {
             $item = $item->all();
         }
         if ($item instanceof Closure || $item instanceof PDO || $item instanceof SimpleXmlElement) {
             $item = 'Unserializable object - ' . get_class($item);
         }
         if ($item instanceof Exception) {
             $item = sprintf('Unserializable object - %s. Error: %s in %s, line %s', get_class($item), $item->getMessage(), $item->getFile(), $item->getLine());
         }
         return $item;
     });
     foreach ($controller->viewVars as $k => $v) {
         // Get the validation errors for Entity
         if ($v instanceof EntityInterface) {
             $errors[$k] = $this->_getErrors($v);
         } elseif ($v instanceof Form) {
             $formError = $v->errors();
             if (!empty($formError)) {
                 $errors[$k] = $formError;
             }
         }
     }
     $this->_data = ['content' => $controller->viewVars, 'errors' => $errors];
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:36,代码来源:VariablesPanel.php

示例11: setInheritableAttributesValues

 public function setInheritableAttributesValues($values, $remplace = false)
 {
     $objectProperties = $this->getInheritableAttributes();
     /*
      * transformation d'une structure array('attributeName'=>$value)
      * vers une structure du type
      *
      * array('attributeName'=>array(
      *  'value'=>$value
      * )
      */
     array_walk_recursive($values, function (&$value, $name) {
         $value = array('value' => $value);
     });
     //on merge les valeurs avec la descriptions des attributs hérités
     if (!$remplace) {
         //si l'on n'écrase pas les valeurs, on merge les attributs hérités avec les valeurs courantes
         if ($currentValues = json_decode($this->getValue('data'), true)) {
             $this->inheritableAttributesValues = array_replace_recursive($currentValues, $objectProperties);
         }
     } else {
         //sinon on reset les valeurs en initialisant juste avec les propriété de l'attribut
         $this->inheritableAttributesValues = $objectProperties;
     }
     $this->inheritableAttributesValues = array_replace_recursive($this->inheritableAttributesValues, $values);
     $this->setValue('data', json_encode($this->inheritableAttributesValues, JSON_PRETTY_PRINT));
     return $this;
 }
开发者ID:ElBiniou,项目名称:superbok,代码行数:28,代码来源:Tag.php

示例12: processRequest

 /**
  * Function processing raw HTTP request headers & body
  * and populates them to class variables. 
  */
 private function processRequest()
 {
     $this->request['resource'] = isset($_GET['RESTurl']) && !empty($_GET['RESTurl']) ? $_GET['RESTurl'] : 'index';
     unset($_GET['RESTurl']);
     $this->request['method'] = strtolower($_SERVER['REQUEST_METHOD']);
     $this->request['headers'] = $this->getHeaders();
     $this->request['format'] = isset($_GET['format']) ? trim($_GET['format']) : null;
     switch ($this->request['method']) {
         case 'get':
             $this->request['params'] = $_GET;
             break;
         case 'post':
             $this->request['params'] = array_merge($_POST, $_GET);
             break;
         case 'put':
             parse_str(file_get_contents('php://input'), $this->request['params']);
             break;
         case 'delete':
             $this->request['params'] = $_GET;
             break;
         default:
             break;
     }
     $this->request['content-type'] = $this->getResponseFormat($this->request['format']);
     if (!function_exists('trim_value')) {
         function trim_value(&$value)
         {
             $value = trim($value);
         }
     }
     array_walk_recursive($this->request, 'trim_value');
 }
开发者ID:kazitanvirahsan,项目名称:simple-rest,代码行数:36,代码来源:Rest.php

示例13: render

 public function render($data)
 {
     $data = array_flip($data);
     $xml = new SimpleXMLElement($this->xmlroot);
     array_walk_recursive($data, array($xml, 'addChild'));
     return $xml->asXML();
 }
开发者ID:nmadipati,项目名称:si-ksc,代码行数:7,代码来源:response_xml.php

示例14: get_data_for_transit

 /**
  * Need to do slightly less with attachments
  *
  * @return array
  */
 public function get_data_for_transit()
 {
     $data = $this->get_data();
     array_walk_recursive($data, array($this, 'object_to_array'));
     array_walk_recursive($data, array($this, 'trim_scalar'));
     return $data;
 }
开发者ID:niko-lgdcom,项目名称:wp-install,代码行数:12,代码来源:attachment.class.php

示例15: render

 /**
  * Render validation errors for the provided $element
  *
  * @param  ElementInterface $element
  * @param  array $attributes
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element, array $attributes = array())
 {
     $messages = $element->getMessages();
     if (empty($messages)) {
         return '';
     }
     if (!is_array($messages) && !$messages instanceof Traversable) {
         throw new Exception\DomainException(sprintf('%s expects that $element->getMessages() will return an array or Traversable; received "%s"', __METHOD__, is_object($messages) ? get_class($messages) : gettype($messages)));
     }
     // Prepare attributes for opening tag
     $attributes = array_merge($this->attributes, $attributes);
     $attributes = $this->createAttributesString($attributes);
     if (!empty($attributes)) {
         $attributes = ' ' . $attributes;
     }
     // Flatten message array
     $escapeHtml = $this->getEscapeHtmlHelper();
     $messagesToPrint = array();
     $self = $this;
     array_walk_recursive($messages, function ($item) use(&$messagesToPrint, $escapeHtml, $self) {
         if (null !== ($translator = $self->getTranslator())) {
             $item = $translator->translate($item, $self->getTranslatorTextDomain());
         }
         $messagesToPrint[] = $escapeHtml($item);
     });
     if (empty($messagesToPrint)) {
         return '';
     }
     // Generate markup
     $markup = sprintf($this->getMessageOpenFormat(), $attributes);
     $markup .= implode($this->getMessageSeparatorString(), $messagesToPrint);
     $markup .= $this->getMessageCloseString();
     return $markup;
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:42,代码来源:FormElementErrors.php


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