Change language

PHP Array_splice () Function

Syntax:
array array_splice ($array1, $start_point, $range, $array2)
Parameters:this function can take four parameters and is described below:
  • $array1 (required):this parameter refers to the original array with which we want to work.
  • $start_point (required):this parameter refers to the starting position of the array from which you want to remove elements. Be sure to include this value. If the supplied value is negative, then the function starts deleting from the end of the array, that is, -1 refers to the last element of the array.
  • $range (optional):this parameter refers to a range, or the limiting point to which the deletion must be performed. A negative value will indicate the amount from the end of the line. This can now also be left blank. If you leave the field blank, the function will delete all values ​​specified at the start point up to the end.
  • $array2 (optional):this refers to another array whose elements are to be inserted into $array1. Now, to insert a single element, we don’t need to provide the entire array. We can just pass one string for one value. For a group of values, we need an array.
  • Returned value:the function will return an array of deleted elements from $start_point to $range.Below is the program illustrates the array_splice() function in PHP:  
    // PHP program to illustrate usage
    // array_splice() functions $array1 = array ( "10" = > " raghav " , " 20 " = > "ram" , " 30 " = > "laxman" , "40" = > "aakash" , " 50 " = > " ravi " ); $array2 = array ( " 60 " = > "ankita" , "70" = > "antara" ); echo " The returned array: " ; print_r ( array_splice ( $array1 , 1, 4, $array2 )); echo " The original array is modified to: " ; print_r ( $array1 );  
    ?>
    Output:
    The returned array : Array ([0] = > ram [1] = > laxman [2] = > aakash [3] = > ravi) The original array is modified to: Array ([0] = > raghav [1 ] = > ankita [2] = > antara)
    Link :
    http://php.net/manual/en/function.array-splice.php

    Shop

    Gifts for programmers

    Best laptop for Excel

    $
    Gifts for programmers

    Best laptop for Solidworks

    $399+
    Gifts for programmers

    Best laptop for Roblox

    $399+
    Gifts for programmers

    Best laptop for development

    $499+
    Gifts for programmers

    Best laptop for Cricut Maker

    $299+
    Gifts for programmers

    Best laptop for hacking

    $890
    Gifts for programmers

    Best laptop for Machine Learning

    $699+
    Gifts for programmers

    Raspberry Pi robot kit

    $150

    Latest questions

    PythonStackOverflow

    Common xlabel/ylabel for matplotlib subplots

    1947 answers

    PythonStackOverflow

    Check if one list is a subset of another in Python

    1173 answers

    PythonStackOverflow

    How to specify multiple return types using type-hints

    1002 answers

    PythonStackOverflow

    Printing words vertically in Python

    909 answers

    PythonStackOverflow

    Python Extract words from a given string

    798 answers

    PythonStackOverflow

    Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

    606 answers

    PythonStackOverflow

    Python os.path.join () method

    384 answers

    PythonStackOverflow

    Flake8: Ignore specific warning for entire file

    360 answers


    Wiki

    Python | How to copy data from one Excel sheet to another

    Common xlabel/ylabel for matplotlib subplots

    Check if one list is a subset of another in Python

    How to specify multiple return types using type-hints

    Printing words vertically in Python

    Python Extract words from a given string

    Cyclic redundancy check in Python

    Finding mean, median, mode in Python without libraries

    Python add suffix / add prefix to strings in a list

    Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

    Python - Move item to the end of the list

    Python - Print list vertically