ArrayObject append() function in PHP

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


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

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.