Ds \ Vector::toArray()函數是PHP中的一個內置函數,用於將向量轉換為數組。向量的所有元素都將複製到數組中。
用法:
array public Ds\Vector::toArray( void )
參數:該函數不接受任何參數。
返回值:此函數返回包含向量的所有元素的數組。
以下示例程序旨在說明PHP中的Ds \ Vector::toArray()函數:
程序1:
<?php
// Declare new Vector
$vect = new \Ds\Vector([3, 6, 1, 2, 9, 7]);
echo("Original vector\n");
// Desplay the vector elements
var_dump($vect);
echo("\nArray elements\n");
// Use toArray() function to convert
// vector to array and display it
var_dump($vect->toArray());
?>輸出:
Original vector
object(Ds\Vector)#1 (6) {
[0]=>
int(3)
[1]=>
int(6)
[2]=>
int(1)
[3]=>
int(2)
[4]=>
int(9)
[5]=>
int(7)
}
Array elements
array(6) {
[0]=>
int(3)
[1]=>
int(6)
[2]=>
int(1)
[3]=>
int(2)
[4]=>
int(9)
[5]=>
int(7)
}
程序2:
<?php
// Declare new Vector
$vect = new \Ds\Vector(["geeks", "for", "geeks"]);
echo("Original vector\n");
// Desplay the vector elements
var_dump($vect);
echo("\nArray elements\n");
// Use toArray() function to convert
// vector to array and display it
var_dump($vect->toArray());
?>輸出:
Original vector
object(Ds\Vector)#1 (3) {
[0]=>
string(5) "geeks"
[1]=>
string(3) "for"
[2]=>
string(5) "geeks"
}
Array elements
array(3) {
[0]=>
string(5) "geeks"
[1]=>
string(3) "for"
[2]=>
string(5) "geeks"
}
參考: http://php.net/manual/en/ds-vector.toarray.php
相關用法
- PHP Ds\Map toArray()用法及代碼示例
- PHP Ds\Set toArray()用法及代碼示例
- PHP Ds\Pair toArray()用法及代碼示例
- PHP Ds\Queue toArray()用法及代碼示例
- PHP Ds\PriorityQueue toArray()用法及代碼示例
- PHP Ds\Collection toArray()用法及代碼示例
- PHP SplFixedArray toArray()用法及代碼示例
- PHP Ds\Deque toArray()用法及代碼示例
- PHP Ds\Stack toArray()用法及代碼示例
- JQuery Misc toArray()用法及代碼示例
- p5.js nf()用法及代碼示例
- PHP dir()用法及代碼示例
注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | Ds\Vector toArray() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
