Open In App

ArrayObject append() function in PHP

Improve
Improve
Like Article
Like
Save
Share
Report

The append() function of the ArrayObject class in PHP is used to append a given value onto an ArrayObject. The value being appended can be a single value or an array itself.

Syntax:

void append($value)  

Parameters: This function accepts a single parameter $value, representing the value to be appended.

Return Value: This function does not returns any value.

Below programs illustrate the above function:

Program 1:




<?php
// PHP function to illustrate the
// append() method
  
$arrObj = new ArrayObject(array('Geeks',
                        'for', 'Geeks'));
  
$arrObj->append('welcomes you');
  
var_dump($arrObj);
  
?>


Output:

object(ArrayObject)#1 (1) {
  ["storage":"ArrayObject":private]=>
  array(4) {
    [0]=>
    string(5) "Geeks"
    [1]=>
    string(3) "for"
    [2]=>
    string(5) "Geeks"
    [3]=>
    string(12) "welcomes you"
  }
}

Program 2:




<?php
// PHP function to illustrate the
// append() method
  
$arrObj = new ArrayObject(array('Geeks',
                        'for', 'Geeks'));
  
// Appending an array
$arrObj->append(array('welcomes', 'you'));
  
var_dump($arrObj);
  
?>


Output:

object(ArrayObject)#1 (1) {
  ["storage":"ArrayObject":private]=>
  array(4) {
    [0]=>
    string(5) "Geeks"
    [1]=>
    string(3) "for"
    [2]=>
    string(5) "Geeks"
    [3]=>
    array(2) {
      [0]=>
      string(8) "welcomes"
      [1]=>
      string(3) "you"
    }
  }
}

Reference: http://php.net/manual/en/arrayobject.append.php



Last Updated : 22 Mar, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads