Skip to content

Instantly share code, notes, and snippets.

@RakibSiddiquee
Last active April 23, 2017 05:21
Show Gist options
  • Save RakibSiddiquee/99de0650d6aebed7021f04014e44800b to your computer and use it in GitHub Desktop.
Save RakibSiddiquee/99de0650d6aebed7021f04014e44800b to your computer and use it in GitHub Desktop.
When we want to replace an element or some elements of an array with an element or an array of elements
<?php
$arr = [100, 200, 300, 400, 500]; // An array containing some values
$new_arr = [2 => 1001]; // Take a new array with a key where we want to keep the value
array_splice($arr, 2, 1, $new_arr); // array_splice(old_array, position_from_where_to_start, no_of_element_of_new_array, new_array)
print_r($arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment