array_pop() function in PHP


The array_pop() function deletes the last element of an array. It returns the value of the last element of the array. If the array is empty, NULL is returned.

Syntax

array_pop(arr)

Parameters

  • arr − The specified array

Return

The array_pop() function returns the last element of the array. If the array is empty, NULL is returned.

The following is an example −

Example

 Live Demo

<?php
$arr = array("laptop", "mobile", "tablet");
$res = array_pop($arr);
print_r($res);
?>

Output

The following is the output −

tablet

Updated on: 23-Dec-2019

39 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements