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. Windows 7 无密码文件共享

    Windows7中创建无密码的文件共享的几个步骤: 在“控制面板\所有控制面板项\网络和共享中心\高级共享设置”开启“关闭密码保护共享”和“启用文件和打印机共享”.关闭密码保护共享的操作会启用Gues ...

  2. scala中Map和Tuple

    /** * Created by root * Description : Tuple and Map */ object MapTest { def main(args: Array[String] ...

  3. Splash plugins_enabled 属性

    plugins_enabled属性可以控制浏览器插件(如 Flash 插件)是否开启.默认情况下,此属性是 false ,表示不开启. function main(splash, args) spla ...

  4. VS2015编译提示无法运行“rc.exe”

    使用VSx64命令行编译项目,提示无法运行“rc.exe” 想办法搜索rc.exe和rcdll.dll这两个文件,然后拷贝到C:\Program Files (x86)\Microsoft Visua ...

  5. 关于Android不能启动的问题

    关于Android不能启动的问题 untracked pid exited[日期:2013-03-26] 来源:Linux社区  作者:Linux [字体:大 中 小]   1.ok6410nandf ...

  6. javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }

    一: 在app的build中android {    ...    defaultConfig {        ...        //添加如下配置就OK了        javaCompileO ...

  7. Handler基本用法

    片断一:mHandler = new Handler();mRunnable = new Runnable() { @Override public void run() { currentPosit ...

  8. 深入浅出MFC——MFC多线程程序设计(七)

    1. 从操作系统层面看线程——三个观念:模块(MDB).进程(PDB).线程(TDB) 2. “执行事实”发生在线程身上,而不在进程身上.也就是说,CPU调度单位是线程而非进程.调度器据以排序的,是每 ...

  9. 使用taro开发钉钉的E应用报错 You are currently using minified code outside of NODE_ENV === "production". This means that you are running a slower development build of Redux. You can use loose-envify (https://git

    今天测试taro转钉钉E应用的时候,在模拟器上没事,但是在真机上却报错了: You are currently using minified code outside of NODE_ENV === ...

  10. Qt——添加动作及对话框

    1. 添加动作 教程:https://www.devbean.net/2012/08/qt-study-road-2-action/ 运行教程中的第一个程序,报错如下: 原因:没有将main.cpp改 ...