ArrayIterator::getArrayCopy()函數是PHP中的內置函數,用於創建數組的副本。
用法:
array ArrayIterator::getArrayCopy( void )
參數:該函數不接受任何參數。
返回值:此函數返回數組的副本。
以下示例程序旨在說明PHP中的ArrayIterator::getArrayCopy()函數:
示例1:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array('G', 'e', 'e', 'k', 's', 'f', 'o', 'r')
);
// Create a copy of array
$copyArr = $arrItr->getArrayCopy();
// Display the array iterator element
var_dump($copyArr);
?>
輸出:
array(8) {
[0]=>
string(1) "G"
[1]=>
string(1) "e"
[2]=>
string(1) "e"
[3]=>
string(1) "k"
[4]=>
string(1) "s"
[5]=>
string(1) "f"
[6]=>
string(1) "o"
[7]=>
string(1) "r"
}
示例2:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array("Geeks", "for", "Geeks")
);
// Append the element into array
$arrItr->append("Computer");
$arrItr->append("Science");
$arrItr->append("Portal");
// Create copy of array iterator
$copyArr = $arrItr->getArrayCopy();
// Display the array element
var_dump($copyArr);
?>
輸出:
array(6) {
[0]=>
string(5) "Geeks"
[1]=>
string(3) "for"
[2]=>
string(5) "Geeks"
[3]=>
string(8) "Computer"
[4]=>
string(7) "Science"
[5]=>
string(6) "Portal"
}
參考: https://www.php.net/manual/en/arrayiterator.getarraycopy.php
相關用法
- PHP ArrayObject getArrayCopy()用法及代碼示例
- PHP ArrayIterator next()用法及代碼示例
- PHP ArrayIterator key()用法及代碼示例
- PHP ArrayIterator getFlags()用法及代碼示例
- PHP ArrayIterator ksort()用法及代碼示例
- PHP ArrayIterator seek()用法及代碼示例
- PHP ArrayIterator offsetSet()用法及代碼示例
- PHP ArrayIterator seek()用法及代碼示例
- PHP ArrayIterator rewind()用法及代碼示例
- PHP ArrayIterator offsetGet()用法及代碼示例
- PHP ArrayIterator offsetUnset()用法及代碼示例
- PHP ArrayIterator setFlags()用法及代碼示例
- PHP ArrayIterator natsort()用法及代碼示例
- PHP ArrayIterator __construct()用法及代碼示例
- PHP ArrayIterator uasort()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | ArrayIterator getArrayCopy() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
