Blogger Information
Blog 55
fans 0
comment 0
visits 50496
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP数组模拟栈与队列操作-0823
Bean_sproul
Original
746 people have browsed it

入栈array_push()   由尾部进

出栈array_pop()   后进后出

入队array_unshift(array)  由头部进

出队array_shift(array)  由头部出

 

实例

<?php 

header("Content-Type: text/html;charset=utf-8");

$user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16];
echo '<pre>',print_r($user,'ture');//输出
echo '当前长度:'.count($user);
echo '<hr>';

// 入栈array_push()   由尾部进

array_push($user, '金钱');
echo '当前长度:'.count($user);
echo '<pre>',print_r($user,'ture');//输出

echo '<hr>';

// 出栈array_pop()   后进后出
array_pop($user);
// echo array_pop($user);
echo '<pre>',print_r($user,'ture');//输出
echo '<hr>';

// 入队array_unshift(array)  由头部进
array_unshift($user,'哈哈哈');
echo '<pre>',print_r($user,'ture');//输出


// 出队array_shift(array)  由头部出
array_shift($user);
echo '<pre>',print_r($user,'ture');//输出


//模拟队列操作: 增删只能在二端进行,不允许同一端进行

?>

运行实例 »

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

 模拟队列操作


实例

<?php 
//模拟队列操作: 增删只能在二端进行,不允许同一端进行
echo '<pre>';
$user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16];
echo '<pre>',print_r($user,'ture');//输出
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);

?>

运行实例 »

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

 


Correction status:Uncorrected

Teacher's comments:
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