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);/*w w w .j  a v a2  s  .c om*/
?>

Result

Related Topic