clock  Mon - Sun 8.00 AM - 8.00 PM
mail  edu@teknowize.com
fb
instagram
play store
pinterest

How to Remove First Element from Array in PHP

  Hariom Prajapati
  22 Jun 2022
  PHP
Imperial Advance Hero Image

How to Remove First Element from Array in PHP

In this tutorial we will learn how to remove first element from array in PHP.

Here we will take two example single dimensional array and multi dimensional array from which we remove first element from array in PHP using array_shift() function.

 

1) Remove first element from single dimensiona array in PHP.

<?php
    $Arrays = ["w3school", "teknowize", "tutorialpoint"];
    array_shift($Arrays);
  echo "<pre>";
    print_r($Arrays);
?> 

 

Output

php

 

2) Remove first element from multi dimensional array in PHP.

<?php
    $online_tutorial = [
        [ "id" => 1, "website" => "w3school"],
        [ "id" => 2, "website" => "teknowize"],
        [ "id" => 3, "website" => "tutorialpoint"],
    ];
    array_shift($online_tutorial);
  echo "<pre>";
    print_r($online_tutorial);
?> 

 

Output

php