国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊 php數(shù)組函數(shù)序列之a(chǎn)rray_splice()

php數(shù)組函數(shù)序列之a(chǎn)rray_splice()

Jun 06, 2016 pm 08:39 PM
array_splice insert element

array_splice() 函數(shù)與 array_slice() 函數(shù)類似,選擇數(shù)組中的一系列元素,但不返回,而是刪除它們并用其它值代替

array_splice定義和用法

array_splice() 函數(shù)與 array_slice() 函數(shù)類似,選擇數(shù)組中的一系列元素,但不返回,而是刪除它們并用其它值代替。

如果提供了第四個參數(shù),則之前選中的那些元素將被第四個參數(shù)指定的數(shù)組取代。

最后生成的數(shù)組將會返回。

語法
array_splice(array,offset,length,array)參數(shù) 描述
array 必需。規(guī)定數(shù)組。
offset 必需。數(shù)值。如果 offset 為正,則從輸入數(shù)組中該值指定的偏移量開始移除。如果 offset 為負,則從輸入數(shù)組末尾倒數(shù)該值指定的偏移量開始移除。
length 可選。數(shù)值。如果省略該參數(shù),則移除數(shù)組中從 offset 到 結(jié)尾的所有部分。如果指定了 length 并且為正值,則移除這么多元素。如果指定了 length 且為負值,則移除從 offset 到數(shù)組末尾倒數(shù) length 為止中間所有的元素。
array 被移除的元素由此數(shù)組中的元素替代。如果沒有移除任何值,則此數(shù)組中的元素將插入到指定位置。

提示和注釋
提示:如果函數(shù)沒有刪除任何元素 (length=0),則替代數(shù)組將從 start 參數(shù)的位置插入。(參見例子 3)

注釋:不保留替代數(shù)組中的鍵。

例子 1
代碼如下:
$a1=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird");
$a2=array(0=>"Tiger",1=>"Lion");
array_splice($a1,0,2,$a2);
print_r($a1);
?>

輸出:

Array ( [0] => Tiger [1] => Lion [2] => Horse [3] => Bird )例子 2
與例子 1 相同,但是輸出返回的數(shù)組:
代碼如下:
$a1=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird");
$a2=array(0=>"Tiger",1=>"Lion");
print_r(array_splice($a1,0,2,$a2));
?>

輸出:

Array ( [0] => Dog [1] => Cat )例子 3
length 參數(shù)設(shè)置為 0:
代碼如下:
$a1=array(0=>"Dog",1=>"Cat");
$a2=array(0=>"Tiger",1=>"Lion");
array_splice($a1,1,0,$a2);
print_r($a1);
?>

輸出:

Array ( [0] => Dog [1] => Tiger [2] => Lion [3] => Cat )
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)