array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'arrayobject.getarraycopy.php', 1 => 'ArrayObject::getArrayCopy', 2 => 'Creates a copy of the ArrayObject', ), 'up' => array ( 0 => 'class.arrayobject.php', 1 => 'ArrayObject', ), 'prev' => array ( 0 => 'arrayobject.exchangearray.php', 1 => 'ArrayObject::exchangeArray', ), 'next' => array ( 0 => 'arrayobject.getflags.php', 1 => 'ArrayObject::getFlags', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/spl/arrayobject/getarraycopy.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

ArrayObject::getArrayCopy

(PHP 5, PHP 7, PHP 8)

ArrayObject::getArrayCopyCreates a copy of the ArrayObject

说明

public ArrayObject::getArrayCopy(): array

Exports the ArrayObject to an array.

参数

此函数没有参数。

返回值

Returns a copy of the array. When the ArrayObject refers to an object, an array of the properties of that object will be returned.

示例

示例 #1 ArrayObject::getArrayCopy() example

<?php
// Array of available fruits
$fruits = array("lemons" => 1, "oranges" => 4, "bananas" => 5, "apples" => 10);

$fruitsArrayObject = new ArrayObject($fruits);
$fruitsArrayObject['pears'] = 4;

// create a copy of the array
$copy = $fruitsArrayObject->getArrayCopy();
var_dump($copy);

?>

以上示例会输出:

array(5) {
  ["lemons"]=>
  int(1)
  ["oranges"]=>
  int(4)
  ["bananas"]=>
  int(5)
  ["apples"]=>
  int(10)
  ["pears"]=>
  int(4)
}