Home  >  Article  >  Backend Development  >  Detailed explanation of the use of ArrayObject exchangeArray() function in PHP

Detailed explanation of the use of ArrayObject exchangeArray() function in PHP

藏色散人
藏色散人Original
2019-03-25 15:52:542658browse

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.

Detailed explanation of the use of ArrayObject exchangeArray() function in PHP

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn