Ds\Deque::__ construct()函数是PHP中的内置函数, 用于创建新实例。
语法如下:
Ds\Deque::__construct( $values )
参数:该函数接受单个参数$值包含可遍历的对象或数组以使用初始值。
下面的程序说明了Ds\Deque::__ construct()PHP中的功能:
程序1:
<
?php // Declare a deque
$deq = new \Ds\Deque();
// Display the elements of deque
echo ( "Elements of first deque:\n" );
var_dump( $deq );
// Declare a deque
$deq = new \Ds\Deque([10, 20, 30, 40, 50, 60]);
// Display the elements of deque
echo ( "\nElements of second deque:\n" );
var_dump( $deq );
?>
输出如下:
Elements of first deque:
object(Ds\Deque)#1 (0) {
}Elements of second deque:
object(Ds\Deque)#2 (6) {
[0]=>
int(10)
[1]=>
int(20)
[2]=>
int(30)
[3]=>
int(40)
[4]=>
int(50)
[5]=>
int(60)
}
程式2:
<
?php // Declare a deque
$deq = new \Ds\Deque([ "geeks" , "for" , "geeks" ]);
// Display the elements of deque
echo ( "Elements of first deque:\n" );
print_r( $deq );
// Declare a deque
$deq = new \Ds\Deque([ 'G' , 'E' , 'E' , 'K' , 'S' , 1, 2, 3]);
// Display the elements of deque
echo ( "\nElements of second deque:\n" );
print_r( $deq );
?>
输出如下:
Elements of first deque:
Ds\Deque Object
(
[0] =>
geeks
[1] =>
for
[2] =>
geeks
)Elements of second deque:
Ds\Deque Object
(
[0] =>
G
[1] =>
E
[2] =>
E
[3] =>
K
[4] =>
S
[5] =>
1
[6] =>
2
[7] =>
3
)
【PHP如何使用Ds\Deque __construct()函数(用法实例)】参考: https://www.php.net/manual/en/ds-deque.construct.php
推荐阅读
- 算法(如何排列给定数字以形成最大数(|S2))
- Python正则表达式(re.search() VS re.findall())
- 热点2.0(Hotspot 2.0)详细指南介绍
- BrowserStack面试体验|S6(校园内)
- Perl循环(foreach、foreach、while、do…while、until嵌套循环)
- 如何在Java 8中打印Stream的元素
- 飞雪桌面日历如何显示明天的天气预报
- 飞雪桌面日历迅速关机为啥会这么快?
- 小米盒子连不上网络的处理办法