php clear(),PHP Ds\Collection clear()用法及代码示例
Ds \ Collection::clear()函数是PHP中的内置函数,用于从集合中删除所有值。
用法:
Ds\Collection::clear( void )
参数:该函数不接受任何参数。
返回值:该函数不返回任何值。
以下示例程序旨在说明PHP中的Ds \ Collection::clear()函数:
范例1:
// Create a collection
$collection = new \Ds\Vector([1, 2, 3, 4, 5, 6]);
// Display the collection element
print_r($collection);
// Use clear() function to remove elements
$collection->clear();
// Display the collection element
print_r($collection);
?>
输出:
Ds\Vector Object (
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
Ds\Vector Object (
)
范例2:
// Create a collection
$collection = new \Ds\Vector([10, 15, 21, 13, 16, 18]);
// Display the collection element
var_dump($collection);
// Use clear() function to remove elements
$collection->clear();
// Display the collection element
var_dump($collection);
?>
输出:
object(Ds\Vector)#1 (6) {
[0]=> int(10)
[1]=> int(15)
[2]=> int(21)
[3]=> int(13)
[4]=> int(16)
[5]=> int(18)
}
object(Ds\Vector)#1 (0) {
}
总结
以上是生活随笔为你收集整理的php clear(),PHP Ds\Collection clear()用法及代码示例的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 在php storm中怎么搭建环境,Ph
- 下一篇: php模板技术smarty,PHP模板技