Ds \ Vector::push()函數是PHP中的內置函數,用於將元素添加到向量的末尾。
用法:
void public Ds\Vector::push( $values )
參數:此函數接受單個參數$values,該參數包含一個或多個然後一個要添加到向量中的元素。
返回值:此函數不返回任何值。
以下示例程序旨在說明PHP中的Ds \ Vector::push()函數:
程序1:
<?php
// Create new vector
$arr1 = new \Ds\Vector([10, 20, 30, 40, 50]);
echo("Original vector elements\n");
print_r($arr1);
// Use push() function to add
// element to the vector
$arr1->push(60);
echo("\nVector after appending the elements\n");
print_r($arr1);
?>
輸出:
Original vector elements Ds\Vector Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 ) Vector after appending the elements Ds\Vector Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 )
程序2:
<?php
// Create new vector
$arr1 = new \Ds\Vector([10, 20, 30, 40, 50]);
echo("Original vector elements\n");
print_r($arr1);
// Use push() function to add
// element to the vector
$arr1->push(...[60, 70]);
echo("\nVector after appending the elements\n");
print_r($arr1);
?>
輸出:
Original vector elements Ds\Vector Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 ) Vector after appending the elements Ds\Vector Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 [6] => 70 )
參考: http://php.net/manual/en/ds-vector.push.php
相關用法
- PHP Ds\Deque push()用法及代碼示例
- PHP Ds\PriorityQueue push()用法及代碼示例
- PHP Ds\Queue push()用法及代碼示例
- Node.js push()用法及代碼示例
- PHP Ds\Sequence push()用法及代碼示例
- PHP SplDoublyLinkedList push()用法及代碼示例
- PHP Ds\Stack push()用法及代碼示例
- p5.js value()用法及代碼示例
注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | Ds\Vector push() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。