CKTIS / PHP
array_push()
Append values to an array passed by reference and return its new element count.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_push(array &$array, mixed ...$values): intAppend values to an array passed by reference and return its new element count. With only the array argument the call returns its current count. The variable itself contains the updated values. Supplying an array as one argument appends it as a single nested element.
Signature
array_push(array &$array, mixed ...$values): int
Example output
[1,3,["A","B",["C","D"]]]
Examples
<?php
$queue = ['A'];
$before = array_push($queue);
$length = array_push($queue, 'B', ['C','D']);
echo json_encode([$before,$length,$queue]);
Result
[1,3,["A","B",["C","D"]]]