<?php// 栈操作$arr = [];// 尾部添加array_push($arr,'id',1);printf('<pre>%s<pre>',print_r($arr,true));echo '<br>';// 尾部删除array_pop($arr);print_r($arr);// printf('<pre>%s<pre>',print_r($arr,true));// 头部增加array_unshift($arr,'name');print_r($arr);// 头部删除array_shift($arr);print_r($arr);// 排序按值// 正常由低到高$res =[3,6,9,8.9,66,'name','ABC'];sort($res);printf('<pre>%s<pre>',print_r($res,true));// 由高到低rsort($res);print_r($res);// 降序但是索引不变$res =[3,6,9,8.9,66,'name','ABC'];arsort($res);print_r($res);// 排序按键// 按键由低到高$res =["b"=>'bag',"f"=>0,"a"=>3.5];ksort($res);print_r($res);// 按键由高到低krsort($res);print_r($res);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号