SplFixedArray::toArray()函數是PHP中的內置函數,用於從固定數組中獲取PHP數組。
用法:
array SplFixedArray::toArray()
參數:該函數不接受任何參數。
返回值:該函數返回一個PHP數組。
以下示例程序旨在說明PHP中的SplFixedArray::toArray()函數:
示例1:
<?php
// Create a fixed size array
$gfg = new SplFixedArray(3);
$gfg[0] = 1;
$gfg[1] = 5;
$gfg[2] = 10;
var_dump($gfg->toArray());
?>
輸出:
array(3) {
[0]=>
int(1)
[1]=>
int(5)
[2]=>
int(10)
}
示例2:
<?php
// Create some fixed size array
$gfg = new SplFixedArray(3);
$gfg1 = new SplFixedArray(6);
$gfg1[0] = 1;
$gfg1[1] = 5;
$gfg1[2] = 10;
$gfg2 = new SplFixedArray(5);
$gfg2[0] = 1;
$gfg2[1] = 5;
$gfg2[2] = 10;
$gfg2[3] = 10;
$gfg2[4] = 20;
// Print result
var_dump($gfg->toArray());
var_dump($gfg1->toArray());
var_dump($gfg2->toArray());
?>
輸出:
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
array(6) {
[0]=>
int(1)
[1]=>
int(5)
[2]=>
int(10)
[3]=>
NULL
[4]=>
NULL
[5]=>
NULL
}
array(5) {
[0]=>
int(1)
[1]=>
int(5)
[2]=>
int(10)
[3]=>
int(10)
[4]=>
int(20)
}
參考: https://www.php.net/manual/en/splfixedarray.toarray.php
相關用法
- PHP SplFixedArray next()用法及代碼示例
- PHP SplFixedArray key()用法及代碼示例
- PHP SplFixedArray offsetExists()用法及代碼示例
- PHP SplFixedArray getSize()用法及代碼示例
- PHP SplFixedArray __construct()用法及代碼示例
- PHP SplFixedArray count()用法及代碼示例
- PHP SplFixedArray current()用法及代碼示例
- PHP SplFixedArray rewind()用法及代碼示例
- PHP SplFixedArray setSize()用法及代碼示例
- PHP SplFixedArray offsetUnset()用法及代碼示例
- PHP SplFixedArray valid()用法及代碼示例
- PHP SplFixedArray offsetGet()用法及代碼示例
- PHP Ds\Set toArray()用法及代碼示例
- PHP Ds\Map toArray()用法及代碼示例
- PHP Ds\Collection toArray()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplFixedArray toArray() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
