PHP Version
4+
$array = ['orange', 'banana', 'apple'];

// Removes the last element from the array
array_pop($array);
print_r($array);
/*
Output:
    Array
    (
        [0] => orange
        [1] => banana
    )
*/
array_pop(array &$array): mixed
// Initialize the array
$array = ['orange', 'banana', 'apple'];

// Remove the last element from the array
$removedItem = array_pop($array);
print_r($array);
/*
Output:
    Array
    (
        [0] => orange
        [1] => banana
    )
*/

echo $removedItem; // Output: 'apple'

// Case 1: Empty array
$emptyArray_1 = [];
$emptyArray_1_removedItem = array_pop($emptyArray_1); // Array is empty, no element to remove

var_dump($emptyArray_1_removedItem); // NULL

// Case 2: Array with one element
$emptyArray_2 = [1];
$emptyArray_2_removedItem = array_pop($emptyArray_2);

var_dump($emptyArray_2_removedItem); // int(1)
$fruits = ['apple', 'banana', 'cherry'];
$removedFruit = array_pop($fruits);
echo $removedFruit; // Outputs: 'cherry'
$fruits = ['apple', 'banana', 'cherry'];
array_pop($fruits);
echo count($fruits); // Outputs: 2
$assocArray = ['name' => 'John', 'age' => 30];
array_pop($assocArray);
print_r($assocArray);
/*
Output:
    Array
    (
        [name] => John
    )
*/
// Original array
$fruits = ['apple', 'banana', 'cherry'];

// Create an empty array to hold reversed elements
$reversedFruits = [];

// Use a loop to pop elements from the original array and add them to the new array
while ($fruit = array_pop($fruits)) {
    $reversedFruits[] = $fruit;
}

// Output the reversed array
print_r($reversedFruits);
/*
Output:
    Array
    (
        [0] => cherry
        [1] => banana
        [2] => apple
    )
*/
$fruits = ['apple', 'banana', 'cherry'];

// Reverse the array
$reversedFruits = array_reverse($fruits);

// Output the reversed array
print_r($reversedFruits);
/*
Output:
    Array
    (
        [0] => cherry
        [1] => banana
        [2] => apple
    )
*/
// Original array
$fruits = ['apple', 'banana', 'cherry'];

// Remove the last element using unset()
unset($fruits[count($fruits) - 1]);

// Output the array
print_r($fruits);
/*
Output:
    Array
    (
        [0] => apple
        [1] => banana
    )
*/