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


PHP ArrayList::explode方法代码示例

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


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

示例1: explode

 /**
  * Splits a string, an array or an ArrayList by one of 4 different methods.
  *      ArrayList (Of any of the 4 object types)
  *      Array (Of any of the 4 object types)
  *      String (To explode by)
  *      Regular Expression (To split by)
  * 
  * This is a powerful tool, but a lot of recursion will occur if using an
  * array and/or an ArrayList.
  * 
  * And 4 basic use cases:
  *      Split a String by a String
  *      Split a String by an Array (nested?) of Strings
  *      Split an Array (nested?) of Strings by a String
  *      Split an Array (nested?) of Strings by an Array (nested?) of Strings
  * 
  * Using Arrays as one of the two parameters can be a tad messy, but easy
  * once you figure it out.
  * 
  * No Matter what an array is returned for each delimiter string and each
  * "split" string, no matter how nested. Using multiple delimiters will not
  * cause the string to be split by multiple delimiters, but instead to split
  * each delimiter into another set of split strings (Refer to line 43).
  * 
  * @param ArrayList|string|array $delimiters The character(s) you're splitting by, can be inside arrays/nested arrays.
  * @param string $string The string you are trying to split.
  * @param bool $allowDuplicates If true then the normal ArrayList "remove duplicate objects" will be ignored, and instead the same value/object may appear in the ArrayList twice.
  * @return ArrayList Split String as an ArrayList, may contain sub-arraylists.
  * @throws Exception
  */
 public static function explode($delimiters, &$string, $allowDuplicates = true)
 {
     if (!is_string($string) && !is_array($string) && !$string instanceof ArrayList) {
         throw new Exception('String is invalid.');
     }
     //$delimiters may be a String (1 delimiter), an ArrayList, an Array or a Regular Expression
     //Array/ArrayList Delimiters
     if ($delimiters instanceof ArrayList) {
         $x = new ArrayList();
         foreach ($delimiters as $delimiter) {
             $x->add($string = ArrayList::explode($delimiter, $string), false, true);
         }
         return $x;
     } else {
         if (is_array($delimiters)) {
             return ArrayList::explode(new ArrayList($delimiters), $string);
             //CHEAP
         } else {
             if (is_string($delimiters)) {
                 if (is_string($string)) {
                     return new ArrayList(explode($delimiters, $string));
                 } else {
                     if (is_array($string)) {
                         return ArrayList::explode($delimiters, new ArrayList($string));
                     } else {
                         if ($string instanceof ArrayList) {
                             $x = new ArrayList();
                             foreach ($string as $str) {
                                 $x->add(ArrayList::explode($delimiters, $str), false, true);
                             }
                             return $x;
                         }
                     }
                 }
             } else {
                 if (@preg_match($delimiters, null) !== false) {
                     //return new ArrayList(preg_split($delimiters, $string));
                 }
             }
         }
     }
     throw new Exception('Invalid Delimiters (Must be Array, ArrayList, Regular Expression or String)');
 }
开发者ID:YourWishes,项目名称:ArrayList,代码行数:73,代码来源:ArrayList.php


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