PHP Version
4+
$array = [1, 2, 3];

// Add a single element to the end of the array
array_push($array, 4);
print_r($array);
/*
Output:
    Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
        [3] => 4
    )
*/

// Add multiple elements to the end of the array
array_push($array, 5, 6, 7);
print_r($array);
/*
Output:
    Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
        [3] => 4
        [4] => 5
        [5] => 6
        [6] => 7
    )
*/
array_push(array &$array, mixed $value1 [, mixed $value2 [, mixed $... ]]): int
$array = [1, 2, 3];

// Add a new element to the end of the array and store the return value
$total_elements = array_push($array, 4);
print_r($array);
/*
Output:
    Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
        [3] => 4
    )
*/

echo "Total number of elements in the array: " . $total_elements;
// Output: Total number of elements in the array: 4
$fruits = ['apple', 'banana', 'cherry'];

// Add elements to the end of the array
array_push($fruits, 'date', 'elderberry');

// Print the updated array
print_r($fruits);

/*
Output:
    Array
    (
        [0] => apple
        [1] => banana
        [2] => cherry
        [3] => date
        [4] => elderberry
    )
*/
$fruits = ['apple', 'banana', 'cherry'];

// Add elements to the end of the array
$fruits[] = 'date';
$fruits[] = 'elderberry';

// Print the updated array
print_r($fruits);

/*
Output:
    Array
    (
        [0] => apple
        [1] => banana
        [2] => cherry
        [3] => date
        [4] => elderberry
    )
*/
$person = array(
    'first_name' => 'John',
    'last_name' => 'Doe',
    'age' => 30
);

// Attempting to add key-value pairs using array_push()
array_push($person, 'email', 'john@example.com', 'city', 'New York');

// Output the array
print_r($person);

/*
Output:
    Array
    (
        [first_name] => John
        [last_name] => Doe
        [age] => 30

        // These entries were added as numeric keys, not key-value pairs
        [0] => email
        [1] => john@example.com
        [2] => city
        [3] => New York
    )
*/
$person = array(
    'first_name' => 'John',
    'last_name' => 'Doe',
    'age' => 30
);

// Add a new key-value pair
$person['address'] = 'Seoul, Korea';

// Output the updated array
print_r($person);

/*
Output:
    Array
    (
        [first_name] => John
        [last_name] => Doe
        [age] => 30
        [address] => Seoul, Korea
    )
*/