PHP - Removing the last element from an array via array_pop() method

Introduction

array_pop() is the counterpart to array_shift().

It removes the last element from an array and returns the element's value.

Demo

<?php


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

         echo array_pop($myBook)."\n"; // Displays"2018"

         print_r($myBook);//from   w  ww.ja  va  2 s  . c  o  m
?>

Result

Related Topic