Пример #1
0
 /**
  * Checks elements in an array against a regexp, and if they match, replaces the value with the specified value.
  * Boolean and null values are unmodified.
  * Other scalar values are matched against the regexp.
  * If $aDeep is true, arrays are processed recursively, otherwise they are unmodified.
  * All other values are unmodified.
  * @param array $aArray Source array.
  * @param string $aRegexp A regular expression to match against.
  * @param mixed $aSubstitute The substitute value which will replace matched values.
  * @param bool $aDeep If true, arrays are processed recursively.
  * @return array The new array.
  */
 public static function substitute($aArray, $aRegexp, $aSubstitute, $aDeep = false)
 {
     $arr = array();
     foreach ($aArray as $k => $v) {
         if (is_bool($v) || is_null($v)) {
             $arr[$k] = $v;
         } else {
             if (is_scalar($v) && preg_match($aRegexp, $v) == 1) {
                 $arr[$k] = $aSubstitute;
             } else {
                 if (is_array($v) && $aDeep == true) {
                     $arr[$k] = StructUtils::substitute($v, $aRegexp, $aSubstitute, true);
                 } else {
                     $arr[$k] = $v;
                 }
             }
         }
     }
     return $arr;
 }