int array_unshift    ( array &$array   , mixed $value1   [, mixed $...  ] )

array_unshift() prepends passed elements to the front   of the array. Note that the list of elements is   prepended as a whole, so that the prepended elements stay in the same   order.  All numerical array keys will be modified to start counting from   zero while literal keys won't be touched.

<?php
$queue = array('a', 'b', 'c');
array_unshift($queue, 'unshift');
w($queue);
$queue = array('a', 'b', 'c');
array_unshift($queue, array('unshift','unshift_1'));
w($queue);
$queue = array('a', 'b', 'c','D'=>'dd');
array_unshift($queue, 'unshift');
w($queue);
$queue = array('a', 'b', 'c','D'=>'dd',array('unshift','unshift_1'));
array_unshift($queue, array('unshift','unshift_1'));
w($queue);
die();
D:\wamp64\www\w0827pm\study.php:109:
array (size=4)
0 => string 'unshift' (length=7)
1 => string 'a' (length=1)
2 => string 'b' (length=1)
3 => string 'c' (length=1)
D:\wamp64\www\w0827pm\study.php:109:
array (size=4)
0 =>
array (size=2)
0 => string 'unshift' (length=7)
1 => string 'unshift_1' (length=9)
1 => string 'a' (length=1)
2 => string 'b' (length=1)
3 => string 'c' (length=1)
D:\wamp64\www\w0827pm\study.php:109:
array (size=5)
0 => string 'unshift' (length=7)
1 => string 'a' (length=1)
2 => string 'b' (length=1)
3 => string 'c' (length=1)
'D' => string 'dd' (length=2)
D:\wamp64\www\w0827pm\study.php:109:
array (size=6)
0 =>
array (size=2)
0 => string 'unshift' (length=7)
1 => string 'unshift_1' (length=9)
1 => string 'a' (length=1)
2 => string 'b' (length=1)
3 => string 'c' (length=1)
'D' => string 'dd' (length=2)
4 =>
array (size=2)
0 => string 'unshift' (length=7)
1 => string 'unshift_1' (length=9)

mixed array_shift    ( array &$array   )

array_shift() shifts the first value of the    array off and returns it, shortening the    array by one element and moving everything   down. All numerical array keys will be modified to start counting from zero   while literal keys won't be touched.

 $queue = array('a', 'b', 'c');
array_shift($queue);
wb($queue);
$queue = array('a', 'b', 'c','D'=>'dd',array('shift','shift_1'));
array_shift($queue);
wb($queue);
echo '----------------------------<br>';
$queue = array('a', 'b', 'c','D'=>'dd',array('shift','shift_1'));
w($queue[count($queue)-2]);
w(current($queue));
w(next($queue));
w(next($queue));
array_shift($queue);
wb($queue); function wb($w){
w($w);
if (is_array($w)) {
w(current($w));
} else {
w('! is_array(var)');
}
}
D:\wamp64\www\w0827pm\study.php:133:
array (size=2)
0 => string 'b' (length=1)
1 => string 'c' (length=1)
D:\wamp64\www\w0827pm\study.php:133:string 'b' (length=1)
D:\wamp64\www\w0827pm\study.php:133:
array (size=4)
0 => string 'b' (length=1)
1 => string 'c' (length=1)
'D' => string 'dd' (length=2)
2 =>
array (size=2)
0 => string 'shift' (length=5)
1 => string 'shift_1' (length=7)
D:\wamp64\www\w0827pm\study.php:133:string 'b' (length=1)
----------------------------
D:\wamp64\www\w0827pm\study.php:133:
array (size=2)
0 => string 'shift' (length=5)
1 => string 'shift_1' (length=7)
D:\wamp64\www\w0827pm\study.php:133:string 'a' (length=1)
D:\wamp64\www\w0827pm\study.php:133:string 'b' (length=1)
D:\wamp64\www\w0827pm\study.php:133:string 'c' (length=1)
D:\wamp64\www\w0827pm\study.php:133:
array (size=4)
0 => string 'b' (length=1)
1 => string 'c' (length=1)
'D' => string 'dd' (length=2)
2 =>
array (size=2)
0 => string 'shift' (length=5)
1 => string 'shift_1' (length=7)
D:\wamp64\www\w0827pm\study.php:133:string 'b' (length=1)

算法提炼是落脚点-php数组-字符串函数的更多相关文章

  1. 关于ES6-{块级作用域 let const 解构赋值 数组 字符串 函数的扩展 箭头函数}

    关于ES6 块级作用域 任何一对花括号({})中的语句集都属于一个块,在块中声明的变量在代码块外都是不可访问的,称之为块级作用域,ES5以前没有块级作用域 let let 是ES6新增的声明变量的一种 ...

  2. PHP函数积累总结(Math函数、字符串函数、数组函数)

    Math函数:10个较常用标红.abs — 绝对值acos — 反余弦acosh — 反双曲余弦asin — 反正弦asinh — 反双曲正弦atan2 — 两个参数的反正切atan — 反正切ata ...

  3. PHP 函数(数组字符串)

    函数四要素:  参数  变量   返回值  函数体 函数分类: 1.有参数的函数: function Show() { echo "hello"; } Show(); 2. 有返回 ...

  4. javascript函数一共可分为五类: ·常规函数 ·数组函数 ·日期函数 ·数学函数 ·字符串函数

    javascript函数一共可分为五类:    ·常规函数    ·数组函数    ·日期函数    ·数学函数    ·字符串函数    1.常规函数    javascript常规函数包括以下9个 ...

  5. php随机数、时间、字符串函数,正则,数组函数

    <?php//1.随机数和时间//echo rand(); //随机数生成器//echo rand(0,10); //生成某个范围内的随机数 //echo time(); //取当前时间戳//e ...

  6. ***php解析JSON二维数组字符串(json_decode函数第二个参数True和False的区别)

    客户端的请求体中的数据:[{"msg_id": 1, "msg_status": "HAS_READ" }, { "msg_id& ...

  7. js数组,字符串,json互相转换函数有哪些

    js数组,字符串,json互相转换函数有哪些 一.总结 一句话总结: JSON.stringify(arr) JSON.parse(jsonString) str.split('') array.jo ...

  8. Js中常用的字符串,数组,函数扩展

    由于最近辞职在家,自己的时间相对多一点.所以就根据prototytpeJS的API,结合自己正在看的司徒大神的<javascript框架设计>,整理了下Js中常用一些字符串,数组,函数扩展 ...

  9. js数组,数字函数,字符串函数,表单验证,hashMap,堆栈,日期函数,call函数

    1.javascript的数组API Js代码 收藏代码 //定义数组 var pageIds = new Array(); pageIds.push('A'); 数组长度 pageIds.lengt ...

随机推荐

  1. 【代码审计】ThinkSNS_V4 任意文件下载漏洞分析

      0x00 环境准备 ThinkSNS官网:http://www.thinksns.com 网站源码版本:ThinkSNS V4  更新时间:2017-09-13 程序源码下载:http://www ...

  2. Webgoat学习笔记

    Webgoat 分为简单版和开发版,具体版本及安装方法详见:https://github.com/WebGoat/WebGoat 本机环境为:Windows+Tomcat,故下载war包,自动解压缩进 ...

  3. Linux 查看目录大小及文件数量命令

    查看当前目录大小: [root@21andy.com]# du -sh 查看指定目录大小: [root@21andy.com]# du -sh /www/21andy.com 查看当前目录文件总数: ...

  4. MongoDB(五)-- 副本集(replica Set)

    一.副本集介绍 搭建副本集是为了实现mongodb高可用. Mongodb(M)表示主节点,Mongodb(S)表示备节点,Mongodb(A)表示仲裁节点.主备节点存储数据,仲裁节点不存储数据.客户 ...

  5. 使用 CSV 文件存储

    将爬取到的数据以 CSV 文件形式存储: import csv import requests req = requests.get("http://www.baidu.com/" ...

  6. C++标准程序库笔记之一

    本篇博客笔记顺序大体按照<C++标准程序库(第1版)>各章节顺序编排. ---------------------------------------------------------- ...

  7. c语言中的内存分配malloc、alloca、calloc、malloc、free、realloc、sbr

    C语言跟内存分配方式 (1) 从静态存储区域分配.内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量,static变量. (2) 在栈上创建.在执行函数时,函数内局部变 ...

  8. codeforces水题100道 第三题 Codeforces Beta Round #47 A. Domino piling (math)

    题目链接:http://www.codeforces.com/problemset/problem/50/A题意:一个NxM的举行中最多能放多少个1x2的矩形.C++代码: #include < ...

  9. 【LeetCode OJ】Majority Element

    题目:Given an array of size n, find the majority element. The majority element is the element that app ...

  10. QT——信号槽

    结合教程,写出如下关于信号槽的代码,将教程中信号槽两种方式写入同一个界面中. #include "mainwindow.h" #include <QApplication&g ...