zoukankan      html  css  js  c++  java
  • 5_PHP数组_3_数组处理函数及其应用_8_数组与数据结构

    以下为学习孔祥盛主编的《PHP编程基础与实例教程》(第二版)所做的笔记。

    数组与数据结构

    1. array_push() 函数

    程序:

    1 <?php
    2 $stack = array("orange","banana");
    3 $counts = array_push($stack,"apple","pear");
    4 print_r($stack);
    5 //Array ( [0] => orange [1] => banana [2] => apple [3] => pear ) 
    6 echo "<br/>";
    7 print_r($counts);
    8 //4
    9 ?>

    输出:

    Array ( [0] => orange [1] => banana [2] => apple [3] => pear ) 
    4

    2. array_pop() 函数

    程序:

    1 <?php
    2 $fruits = array('apple','banana','orange','pear');
    3 $stack = array_pop($fruits);
    4 print_r($fruits);
    5 //Array ( [0] => apple [1] => banana [2] => orange )
    6 echo "<br/>";
    7 print_r($stack);
    8 //pear
    9 ?>

    输出:

    Array ( [0] => apple [1] => banana [2] => orange ) 
    pear

    3. array_unshift() 函数

    程序:

    1 <?php
    2 $fruits = array('apple','banana');
    3 $counts = array_unshift($fruits,"orange");   //在队首插入
    4 $counts = array_unshift($fruits,"pear");
    5 print_r($fruits);   
    6 //Array ( [0] => pear [1] => orange [2] => apple [3] => banana ) 
    7 echo "<br/>";
    8 echo $counts;        //4
    9 ?>

    输出:

    Array ( [0] => pear [1] => orange [2] => apple [3] => banana ) 
    4

    4. array_shift() 函数

    程序:

    1 <?php
    2 $fruits = array('apple','banana','pear');
    3 $counts = array_shift($fruits);   //在队首删除
    4 //Array ( [0] => banana [1] => pear ) 
    5 print_r($fruits);
    6 echo "<br/>";
    7 echo $counts;        //apple
    8 ?>

    输出:

    Array ( [0] => banana [1] => pear ) 
    apple
  • 相关阅读:
    设计说明书 转
    软件项目详细设计文档规范
    记帐凭证怎样分类?
    Delphi中WideString类型如何转化成String类型
    更靠谱的横竖屏检测方法
    超级小的web手势库AlloyFinger发布
    狗日的rem
    js 面试的坑
    【腾讯Bugly干货分享】基于 Webpack & Vue & Vue-Router 的 SPA 初体验
    移动端 关于 键盘将input 框 顶上去的解决思路---个人见解
  • 原文地址:https://www.cnblogs.com/xiaoxuStudy/p/11827873.html
Copyright © 2011-2022 走看看