Blogger Information
Blog 57
fans 0
comment 0
visits 47159
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用数组来模拟堆栈和队列操作
藍錄的博客
Original
732 people have browsed it

实例

<?php
/**
 * 使用数组来模拟堆栈和队列操作
 */
$user = ['id'=>5, 'name'=>'peter','gender'=>'male'];
echo '<pre>',print_r($user,true);
//echo '当前长度: '. count($user), '<br>';
// 入栈:array_push()返回新数组的长度= count()
//echo array_push($user, 'php中文网');
//echo '当前长度: '. count($user), '<br>';
//print_r($user);

//echo array_pop($user),'<br>';
//echo array_pop($user),'<br>';
//echo array_pop($user),'<br>';
//print_r($user);
//队: shift(),unshift()
//echo array_unshift($user, 'www.php.cn','peterzhu');
//print_r($user);
//echo array_shift($user),'<br>';
//print_r($user);
//模拟队列操作: 增删只能在二端进行,不允许同一端进行
array_push($user, 'php'); //尾部进队
print_r($user);

array_shift($user); // 头部出队
print_r($user);

array_unshift($user, 'html'); // 头部进队
print_r($user);

array_pop($user);  // 尾部出队
print_r($user);

运行实例 »

点击 "运行实例" 按钮查看在线实例

 

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post