Syntax :
ArrayObject exchangeArray ($inputArray)
Parameters : This function takes a single parameter
$inputArray, which is the new array with which the old array will be replaced in the ArrayObject.
Return value : This function returns the old array.The programs below illustrate the above function:
Program 1 :
// PHP illustration program
// exchangeArray() function
$arr
=
array
(
"a"
= >
"engineer"
,
"b"
= >
"are"
,
"c"
= >
"awesome"
);
// Create array object
$arrObject
=
new
ArrayObject (
$arr
);
// New array
$newArr
=
array
(
"1"
= >
"New"
,
"2"
= >
"Array"
);
// Exchange arrays in ArrayObject
$arrObject
-> exchangeArray (
$newArr
);
print_r (
$arrObject
);
?>
Exit:ArrayObject Object ( [storage: ArrayObject: private] = > Array ([1] = > New [2] = > Array))
Program 2 :
// PHP illustration program
// exchangeArray() function
$arr
=
array
(
"a"
= >
"Welcome"
,
"b"
= >
"2"
,
"c"
= >
"GFG"
);
// Create array object
$arrObject
=
new
ArrayObject (
$arr
);
// New array
$newArr
=
array
(
"1"
= >
"Hello"
,
"2"
= >
"World"
);
// Exchange arrays in ArrayObject
$arrObject
-> exchangeArray (
$newArr
);
print_r (
$arrObject
);
?>
Exit:ArrayObject Object ( [storage: ArrayObject: private] = > Array ([1] = > Hello [2] = > World))
Link : http://php.net/manual/en/arrayobject.exchangearray.php