Slicing (splitting) and merging arrays in PHP

This tutorial explains how to splice (split) an array into more than one array by specifying a new array and where to split the existing array, and also how to merge two arrays into a single array. Watch the video below and then scroll down to see the sample code.

Sample PHP code:

  // slicing (splitting) arrays using the array_slice function
  $heroes = array("hulk","wonder woman","superman","iron man");
  $new_heroes = array_slice($heroes,1,3);
  foreach($new_heroes as $value){
    echo "$value </br>";

  // merging arrays using the array_merge function
  $more_heroes = array("spider-man","batman");
  $all_heroes = array_merge($heroes,$more_heroes);
  foreach($all_heroes as $value){
    echo "$value </br>";