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);/*w  w w.j av a2 s.com*/
?>

Result

Related Topic