PHP - Removing the first element from array via array_shift()

Introduction

array_shift() removes the first element from an array, and returns its value (but not its key).

To use it, pass the array in question to array_shift() :

Demo

<?php

          $myBook = array("title"=> "Java",
                          "author"=> "John A",
                          "pubYear"=>  2018);

          echo array_shift($myBook)."\n";

          print_r($myBook);/*ww w  . j av  a  2 s  .co m*/
?>

Result

Related Topic