PHP中的数组(数据结构)

array_pop 将数组最后一个单元弹出(出栈)

$arr = [11=>11,22=>22,33=>33,44=>44]; print_r($arr); array_pop($arr); print_r($arr); Array ( [11] => 11 [22] => 22 [33] => 33 [44] => 44 ) Array ( [11] => 11 [22] => 22 [33] => 33 )

array_push 将一个或多个单元压入数组的末尾(入栈)
$arr = [11=>11,22=>22,33=>33,44=>44]; print_r($arr); array_push($arr,55); print_r($arr); Array ( [11] => 11 [22] => 22 [33] => 33 [44] => 44 ) Array ( [11] => 11 [22] => 22 [33] => 33 [44] => 44 [45] => 55 )

array_shift 将数组开头的单元移出数组
$arr = [11=>11,22=>22,33=>33,44=>44]; print_r($arr); array_shift($arr); print_r($arr); Array ( [0] => 22 [1] => 33 [2] => 44 )

array_unshift 【PHP中的数组(数据结构)】在数组开头插入一个或多个单元
$arr = [11=>11,22=>22,33=>33,44=>44]; print_r($arr); array_unshift($arr, 55); print_r($arr); Array ( [11] => 11 [22] => 22 [33] => 33 [44] => 44 )

参考
  • PHP手册

    推荐阅读