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 ");

 

转载于:https://www.cnblogs.com/jingjingdidunhe/p/6892344.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值