算法提炼是落脚点-php数组-字符串函数

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.

 1 $queue = array(‘a‘, ‘b‘, ‘c‘);
 2 array_shift($queue);
 3 wb($queue);
 4 $queue = array(‘a‘, ‘b‘, ‘c‘,‘D‘=>‘dd‘,array(‘shift‘,‘shift_1‘));
 5 array_shift($queue);
 6 wb($queue);
 7 echo ‘----------------------------<br>‘;
 8 $queue = array(‘a‘, ‘b‘, ‘c‘,‘D‘=>‘dd‘,array(‘shift‘,‘shift_1‘));
 9 w($queue[count($queue)-2]);
10 w(current($queue));
11 w(next($queue));
12 w(next($queue));
13 array_shift($queue);
14 wb($queue);
15
16 function wb($w){
17     w($w);
18     if (is_array($w)) {
19         w(current($w));
20     } else {
21         w(‘! is_array(var)‘);
22     }
23 }
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)
时间: 2024-12-24 08:02:24

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

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

由于最近辞职在家,自己的时间相对多一点.所以就根据prototytpeJS的API,结合自己正在看的司徒大神的<javascript框架设计>,整理了下Js中常用一些字符串,数组,函数扩展,一来可以练练手,二来也锻炼下自己的代码能力.由于代码里面的注释自认为已经非常详细,所以就直接贴代码了. 1. 字符串扩展: ;(function() { var method, stringExtends = { /** * 删除字符串开始和结尾的空白 * @returns {string} */ stri

PHP数组和字符串函数

1.1关于数组操作的函数 1.1.1range(start,end) 创建一个数组,值从start开始,一直到end结束 如果range里面的参数是数字,那么他直接按照数字大小的顺序排序,如果里面的参数是一个字符,那么他将按照ascii编码的顺序排序. 1.1.2array_rand() 随机取出一个数组的下标 array_rand存在第二个参数,默认情况下是1,代表获取一个数组元素的下标,他的数据类型等同于下标的数据类型,但是如果一次性随机获取多个元素的下标,他返回的是一个数组. 虽然他是随机

字符串函数,时间函数,数学函数,数组

字符串函数 strlen 获取字符串的长度,这里的长度是指该字符串的字节的长度! substr 从指定字符串中的指定位置开始,截取指定长度的字符!sub在这里是截取的意思,substr就是字符串截取函数 需要三个参数: 1, 指定的字符串 2, 截取起始位置(以0开始) 3, 截取的长度 strtolower | strtoupper 把字符串全部转换为小写|大写!  仅针对英文有效,也针对汉字中的英文有效! strrev 把字符串反转! strpos 从左往右查找并返回字符串中某个字符的起始位

C语言学习笔记:19_数组-字符数组与字符串(常用字符串函数)

/* * 19_数组-字符数组与字符串.c * * Created on: 2015年7月7日 * Author: zhong */ #include <stdio.h> #include <stdlib.h> #include <string.h> /** *一:字符数组:就是存放字符的char[]数组 * 由于c语言中没有像java,C#中的String(字符串),只有存放字符 的字符型数组当字符串使用(java中的String类也是对字符数组进行封闭的). * *

Javascript学习笔记First day(字符串和数组常用函数)

这些之前有学习过,但是工作中已经很长时间没有接触前端了,所以重新温习一下. $ 在控制台输出一条信息 console console.log(); console.error(); console.warn(); console.info(); $ 常用字符串操作函数 console.log(person.city.length); console.log(person.city.toUpperCase()); console.log(person.city.toLowerCase()); co

前端学PHP之字符串函数

前面的话 字符串的处理和分析在任何编程语言中都是一个重要的基础,往往是简单而重要的.信息的分类.解析.存储和显示,以及网络中的数据都需要操作字符串来完成.尤其在web开发中更为重要,程序员大部分工作都是在操作字符串,本文将详细介绍php中的字符串函数 [注意]关于javascript中字符串的属性和方法移步至此 特点 因为php是弱类型语言,所以其他类型的数据一般都可以直接应用于字符串操作函数中,而自己转换成字符串类型进行处理 echo substr( "1234567", 2, 4

PHP常用操作的字符串函数

PHP常用字符串的操作函数 字符串转换类函数 addcslashes函数:以C语言风格使用反斜线转义字符串中的字符 addslashes函数:使用反斜线引用字符串 chop函数:清除字符串中的连续空格 get_html_translation_table函数:返回htmlspecialchars()函数和htmlentities()函数的转换表 chunk_split函数:将字符串分割成小块 hebrev函数:转换希伯来逻辑字符为可见字符 hebrevc函数:转换希伯来语文本为可见文本,包括换行

php常用的字符串函数

addslashes -- 使用反斜线引用字符串 chr -- 返回相对应于 ascii 码值所指定的单个字符. chunk_split -- 将字符串分割成小块 count_chars --  返回字符串所用字符的信息 crc32 -- 计算一个字符串的 crc32 多项式 crypt – 将字符串用DES编码加密 echo – 输出一个或者是多个字符串 explode -- 使用一个字符串分割另一个字符串 sprintf – 格式化一个字符串并输出 html_entity_decode – 

php基础知识总结(3)字符串函数string

一.大小写转换 1.strtolower()--转换为小写. echo strtolower("Hello WORLD!"); //hello world! 2.strtoupper()--转换为大写. echo strtoupper("Hello WORLD!"); //HELLO WORLD! 3.ucfirst()--把首字母转换为大写. echo ucfirst("hello world");     //Hello world 4.uc