ArrayObject exchangeArray() function in PHP
Last Updated :
22 Mar, 2019
The exchangeArray() function of the ArrayObject class in PHP is used to exchange an array from an ArrayObject. That is, it replaces existing array from an ArrayObject with a newly described array.
Syntax:
ArrayObject exchangeArray( $inputArray )
Parameters: This function accepts a single parameter $inputArray which is the new array with which the old array will be exchanged in the ArrayObject.
Return Value: This function returns the old array.
Below programs illustrate the above function:
Program 1:
<?php
$arr = array ( "a" => "geeks" , "b" => "are" , "c" => "awesome" );
$arrObject = new ArrayObject( $arr );
$newArr = array ( "1" => "New" , "2" => "Array" );
$arrObject ->exchangeArray( $newArr );
print_r( $arrObject );
?>
|
Output:
ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[1] => New
[2] => Array
)
)
Program 2:
<?php
$arr = array ( "a" => "Welcome" , "b" => "2" , "c" => "GFG" );
$arrObject = new ArrayObject( $arr );
$newArr = array ( "1" => "Hello" , "2" => "World" );
$arrObject ->exchangeArray( $newArr );
print_r( $arrObject );
?>
|
Output:
ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[1] => Hello
[2] => World
)
)
Reference: http://php.net/manual/en/arrayobject.exchangearray.php
Share your thoughts in the comments
Please Login to comment...