The exchangeArray() function of the ArrayObject class in PHP is used to exchange arrays from ArrayObject. That is, it replaces the existing array from ArrayObject with a newly described array.
Syntax:
ArrayObject exchangeArray( $inputArray )
Parameters: This function accepts a parameter $inputArray, which is a new array with which the old array will be exchanged in ArrayObject.
Return value: This function returns the old array.
Example 1:
<?php $arr = array("a" => "geeks", "b" => "are", "c" => "awesome"); // 创建数组对象 $arrObject = new ArrayObject($arr); // 新数组 $newArr = array("1" => "New", "2" => "Array"); // 在ArrayObject中交换数组 $arrObject->exchangeArray($newArr); print_r($arrObject);
Output:
ArrayObject Object ( [storage:ArrayObject:private] => Array ( [1] => New [2] => Array ) )
Example 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 ) )
Related recommendations: "PHP Tutorial"
This article is about the introduction of the ArrayObject exchangeArray() function in PHP, I hope Help those in need!
The above is the detailed content of Detailed explanation of the use of ArrayObject exchangeArray() function in PHP. For more information, please follow other related articles on the PHP Chinese website!