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'

// Empty array
$empty_array = [];
$empty_array_removed_item = array_pop($empty_array); // Array is empty, no element to remove

var_dump($empty_array_removed_item); // Output: NULL
$fruits = ['apple', 'banana', 'cherry'];
$removedFruit = array_pop($fruits);
echo $removedFruit; // Output: 'cherry'
$fruits = ['apple', 'banana', 'cherry'];
array_pop($fruits);
echo count($fruits); // Output: 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
    )
*/