zoukankan      html  css  js  c++  java
  • PHP array_splice

    1.函数的作用:数组中元素的删除和替代

    2.函数的参数:

      @params array  &$array

      @params int      $offset

      @params int      $length

      @params array  $replacement_array

    3.例子:

     1 <?php
     2 /**
     3  * http://php.net/manual/zh/function.array-splice.php
     4  * 
     5  * @param $input
     6  * @param $offset
     7  * @param null $length
     8  * @param string $splice
     9  * @return string
    10  */
    11 function str_splice($input, $offset, $length=null, $splice='')
    12 {
    13     $input = (string)$input;
    14     $splice = (string)$splice;
    15     $count = strlen($input);
    16 
    17     // Offset handling (negative values measure from end of string)
    18     if ($offset<0) $offset = $count + $offset;
    19 
    20     // Length handling (positive values measure from $offset; negative, from end of string; omitted = end of string)
    21     if (is_null($length)) $length = $count;
    22     elseif ($length < 0)  $length = $count-$offset+$length;
    23 
    24     // Do the splice
    25     return substr($input, 0, $offset) . $splice . substr($input, $offset+$length);
    26 }
    27 
    28 $string = "The fox jumped over the lazy dog.";
    29 
    30 // Outputs "The quick brown fox jumped over the lazy dog."
    31 echo str_splice($string, 4, 0, "quick brown ");
    学习记录,方便复习
  • 相关阅读:
    WeakReference 在android中的应用
    安卓软键盘监听
    css常用布局
    centos升级vim
    修复svn hook导致的字符集错误
    centos上安装redmine
    nginx安装echo模块
    用阿里云的免费 SSL 证书让网站从 HTTP 换成 HTTPS
    tomcat配置https
    centos 升级nginx到1.10.2
  • 原文地址:https://www.cnblogs.com/jingjingdidunhe/p/6892344.html
Copyright © 2011-2022 走看看