php8.5
Home/ Manual/ spl / arrayobject/ ArrayObject::append

ArrayObject::append

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Appends the value

Description

ArrayObject::append(mixed $value): void

Appends a new value as the last element.

Note

This method cannot be called when the ArrayObject was constructed from an object. Use ArrayObject::offsetSet instead.

Parameters

value

The value being appended.

Return Values

Void

Examples

ArrayObject::append example

php
<?php
$arrayobj = new ArrayObject(array('first','second','third'));
$arrayobj->append('fourth');
$arrayobj->append(array('five', 'six'));
var_dump($arrayobj);
?>

The above example will output:

output
object(ArrayObject)#1 (1) {
  ["storage":"ArrayObject":private]=>
  array(5) {
    [0]=>
    string(5) "first"
    [1]=>
    string(6) "second"
    [2]=>
    string(5) "third"
    [3]=>
    string(6) "fourth"
    [4]=>
    array(2) {
      [0]=>
      string(4) "five"
      [1]=>
      string(3) "six"
    }
  }
}

See Also

  • ArrayObject::offsetSet

Source: reference/spl/arrayobject/append.xml · from the official PHP manual (php/doc-en)