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


PHP Arrays::arrayize方法代码示例

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


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

示例1: builder

 /**
  * Pomůcka pro sestavení adresy s GET parametry.
  * @param array $params Asociativní pole [název-parametru] => hodnota-parametru. Null pro odstranění daného parametru, byl-li tam.
  * Hodnota může být array, pak se automaticky převede na několik samostatných parametrů ve tvaru název-parametru[]
  * @param string $originalUrl Původní adresa
  * @param bool $clear True = všechny GET parametry z $original URL vyhodit a pouze přidávat ty z $params
  * @param bool $clearArrays Jak se má chovat, když v $originalUrl je nějaký parametr - pole (s [] na konci) a v $params také.
  * False = sloučit obě pole. True = smazat to z $originalUrl a nechat jen hodnoty z $params.
  * @param array $keepEntities Array entit, které se nemají enkódovat (např. %id%)
  * @return string
  */
 static function builder($params, $originalUrl, $clear = false, $clearArrays = true, $keepEntities = array())
 {
     $origParams = array();
     if (!$clear) {
         $query = parse_url($originalUrl, PHP_URL_QUERY);
         if ($query) {
             parse_str($query, $origParams);
         }
         if (!$origParams) {
             $origParams = array();
         }
     }
     if ($clearArrays) {
         $finalParams = array_merge($origParams, $params);
     } else {
         $finalParams = array_replace_recursive($origParams, $params);
     }
     foreach ($finalParams as $i => $r) {
         if ($r === null) {
             unset($finalParams[$i]);
         }
     }
     $casti = array();
     foreach ($finalParams as $i => $p) {
         if (is_array($p)) {
             foreach ($p as $pi => $pp) {
                 $casti[] = $i . "[" . urlencode($pi) . "]=" . urlencode($pp);
             }
         } else {
             $casti[] = $i . "=" . urlencode($p);
         }
     }
     if (Strings::strpos($originalUrl, "?") !== false) {
         $zaklad = Strings::substr($originalUrl, 0, Strings::strpos($originalUrl, "?"));
     } else {
         $zaklad = $originalUrl;
     }
     $vrat = $zaklad;
     if ($casti) {
         $vrat .= "?" . implode("&", $casti);
     }
     if ($keepEntities) {
         foreach (Arrays::arrayize($keepEntities) as $ent) {
             $entEncoded = urlencode($ent);
             $vrat = str_replace($entEncoded, $ent, $vrat);
         }
     }
     return $vrat;
 }
开发者ID:ondrakoupil,项目名称:tools,代码行数:60,代码来源:Url.php

示例2: normalizeAttributesArray

 /**
  * Validate and normalize an array with attributes.
  *
  * This function takes in an associative array with attributes, and parses and validates
  * this array. On success, it will return a normalized array, where each attribute name
  * is an index to an array of one or more strings. On failure an exception will be thrown.
  * This exception will contain an message describing what is wrong.
  *
  * @param array $attributes The array containing attributes that we should validate and normalize.
  *
  * @return array The normalized attributes array.
  * @throws \InvalidArgumentException If input is not an array, array keys are not strings or attribute values are
  *     not strings.
  *
  * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
  * @author Jaime Perez, UNINETT AS <jaime.perez@uninett.no>
  */
 public static function normalizeAttributesArray($attributes)
 {
     if (!is_array($attributes)) {
         throw new \InvalidArgumentException('The attributes array is not an array, it is: ' . print_r($attributes, true) . '".');
     }
     $newAttrs = array();
     foreach ($attributes as $name => $values) {
         if (!is_string($name)) {
             throw new \InvalidArgumentException('Invalid attribute name: "' . print_r($name, true) . '".');
         }
         $values = Arrays::arrayize($values);
         foreach ($values as $value) {
             if (!is_string($value)) {
                 throw new \InvalidArgumentException('Invalid attribute value for attribute ' . $name . ': "' . print_r($value, true) . '".');
             }
         }
         $newAttrs[$name] = $values;
     }
     return $newAttrs;
 }
开发者ID:PitcherAG,项目名称:simplesamlphp,代码行数:37,代码来源:Attributes.php


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