HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

array_push

Description

The array_push of Array for PHP pushes one or more elements onto the end of array.

Syntax

array_push(
    array &$array,
    mixed ...$values
): int

Parameters

array

The input array.

values

The values to push onto the end of the array.

Return

Returns the new number of elements in the array.

Examples

1 · array values · one

<?

$array =
[
    "apple",
    "banana",
    "coconut"
];
$values = "date";

array_push($array, $values);

print_r($array);
Array
(
    [0] => apple
    [1] => banana
    [2] => coconut
    [3] => date
)

2 · array values · multiple

<?

$array =
[
    "apple",
    "banana",
    "coconut"
];
$values1 = "date";
$values2 =
[
    "grape",
    "orange"
];
$values3 =
[
    "pineapple",
    "strawberry",
    "watermelon"
];

array_push($array, $values1, $values2, $values3);

print_r($array);
Array
(
    [0] => apple
    [1] => banana
    [2] => coconut
    [3] => date
    [4] => Array
        (
            [0] => grape
            [1] => orange
        )

    [5] => Array
        (
            [0] => pineapple
            [1] => strawberry
            [2] => watermelon
        )

)

3 · return

<?

$array =
[
    "apple",
    "banana",
    "coconut"
];
$values1 = "date";
$values2 =
[
    "grape",
    "orange"
];
$values3 =
[
    "pineapple",
    "strawberry",
    "watermelon"
];

$return = array_push($array, $values1, $values2, $values3);

print_r($return);
6