
- PHP Tutorial
- PHP - Home
- PHP - Introduction
- PHP - Environment Setup
- PHP - Syntax Overview
- PHP - Variable Types
- PHP - Constants
- PHP - Operator Types
- PHP - Decision Making
- PHP - Loop Types
- PHP - Arrays
- PHP - Strings
- PHP - Web Concepts
- PHP - GET & POST
- PHP - File Inclusion
- PHP - Files & I/O
- PHP - Functions
- PHP - Cookies
- PHP - Sessions
- PHP - Sending Emails
- PHP - File Uploading
- PHP - Coding Standard
- Advanced PHP
- PHP - Predefined Variables
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Bugs Debugging
- PHP - Date & Time
- PHP & MySQL
- PHP & AJAX
- PHP & XML
- PHP - Object Oriented
- PHP - For C Developers
- PHP - For PERL Developers
- PHP Form Examples
- PHP - Form Introduction
- PHP - Validation Example
- PHP - Complete Form
- PHP login Examples
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP AJAX Examples
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML Example
- PHP - XML Introduction
- PHP - Simple XML
- PHP - Simple XML GET
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Frame Works
- PHP - Frame Works
- PHP - Core PHP vs Frame Works
- PHP Design Patterns
- PHP - Design Patterns
- PHP Function Reference
- PHP - Built-In Functions
- PHP Useful Resources
- PHP - Questions & Answers
- PHP - Useful Resources
- PHP - Discussion
PHP - Function array_splice()
Syntax
array_splice ( $input, $offset [,$length [,$replacement]] );
Definition and Usage
This function removes the elements designated by offset and length from the input array, and replaces them with the elements of the replacement array, if supplied. It returns an array containing the extracted elements.
Parameters
Sr.No | Parameter & Description |
---|---|
1 |
input(Required) It specifies an array |
2 | offset It specifies where the function will start removing elements. 0 = the first element. |
3 |
length(Optional) It specifies how many elements will be removed, and also length of the returned array. |
4 |
replacement(Optional) It specifies an array with the elements that will be inserted to the original array. |
Return Values
It returns the last value of the array, shortening the array by one element.
Example
Try out following example −
<?php $input = array("red", "black", "pink", "white"); array_splice($input, 2); print_r($input); print_r("<br />"); $input = array("red", "black", "pink", "white"); array_splice($input, 1, -1); print_r($input); print_r("<br />"); $input = array("red", "black", "pink", "white"); array_splice($input, 1, count($input), "orange"); print_r($input); print_r("<br />"); $input = array("red", "black", "pink", "white"); array_splice($input, -1, 1, array("black", "maroon")); print_r($input); print_r("<br />"); $input = array("red", "black", "pink", "white"); array_splice($input, 3, 0, "purple"); print_r($input); print_r("<br />"); ?>
This will produce the following result −
Array ( [0]=>red [1] =>black ) Array ( [0]=>red [1] =>white ) Array ( [0]=>red [1] =>orange ) Array ( [0]=>red [1] =>black [2]=>pink [3]=>black [4]=>maroon ) Array ( [0]=>red [1] =>black [2]=>pink [3]=>purple [4]=>white )
php_function_reference.htm
Advertisements