English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP array_splice() Function Usage and Example
Syntax
Definition and UsageThis function frominputIt specifies an arraydelete the elements in the array byandlengthThe specified element, andreplacement
Replace the elements of the array (if provided) with them. It returns an array containing the extracted elements.
Parameter | Serial Number |
---|---|
1 | Parameters and Description input(required) |
2 | It specifies an array offset |
3 | It specifies where the function will start deleting elements. 0 = the first element. length(optional) |
4 | It specifies the number of elements to be deleted and the length of the returned array. replacement(optional) |
Return Value
Online Example
Example , array("black", "maroon")); $input = array("red", "black", "pink", "white"); 2<?php , 0, "purple"); print_r($input); /print_r("<br , array("black", "maroon")); $input = array("red", "black", "pink", "white"); 1, count($input), "orange"); -1<?php , 0, "purple"); print_r($input); /print_r("<br , array("black", "maroon")); $input = array("red", "black", "pink", "white"); 1); , 0, "purple"); print_r($input); /print_r("<br , array("black", "maroon")); $input = array("red", "black", "pink", "white"); -1, count($input), "orange"); 1, , 0, "purple"); print_r($input); /print_r("<br , array("black", "maroon")); $input = array("red", "black", "pink", "white"); 3array_splice($input, , 0, "purple"); print_r($input); /print_r("<br });?>/Test and see‹
›
Array ( [0]=>red [1Output Result: Array ( [0]=>red [1] =>black ) Array ( [0]=>red [1] =>white ) Array ( [0]=>red [1] =>black [2pink [3] =>orange )4maroon ) Array ( [0]=>red [1] =>black [2pink [3purple [4white )