Blogger Information
Blog 28
fans 0
comment 0
visits 49199
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
小知识记忆
益伦的博客
Original
745 people have browsed it


print输出不用括号

print_r()输出带括号

0、想要在html中嵌入php代码,html文件需要改成php后缀

1、将数组的key全部转为大写或者小写,默认小写

$a=array("a"=>"Cat","b"=>"Dog","c"=>"Horse","1"=>"Horse");

print_r(array_change_key_case($a,CASE_UPPER));//CASE_LOWER 默认值

2、合并两个数组来创建一个新数组

$a1=array("a","b","c","d");

$a2=array("Cat","Dog","Horse","Cow");

print_r(array_combine($a1,$a2));

3、统计数组中所有值出现的次数在数组中出现的次数

$a=array("Cat","Dog","Horse","Dog");

print_r(array_count_values($a));

4、比较第一个数组有单第二个数组没有的成员 Array ( [0] => Cat )

$a1=array(0=>"Cat",1=>"Dog",2=>"Horse");

$a2=array(3=>"Horse",4=>"Dog",5=>"Fish");

print_r(array_diff($a1,$a2));

5、array_diff_assoc() 比较键名和键值,并返回两个数组的差集数组。

6、用指定内容填充数组,从第几个开始,填充几个,填充什么内容

$a=array_fill(2,3,"Dog");

print_r($a);

7、交换数组的key和value

$a=array(0=>"Dog",1=>"Cat",2=>"Horse");

print_r(array_flip($a));

8、计算数组的交集,以第一个数组的key为准

$a1=array(0=>"Cat",1=>"Dog",2=>"Horse");

$a2=array(3=>"Horse",4=>"Dog",5=>"Fish");

print_r(array_intersect($a1,$a2));

9、判断key是否存在

$a=array("a"=>"Dog","b"=>"Cat");

print_r(array_key_exists("a",$a));

10、返回所有的key

$a=array("a"=>"Horse","b"=>"Cat","c"=>"Dog");

print_r(array_keys($a));

11、将两个数组合并成一个数组

$a1=array("a"=>"Horse","b"=>"Dog");

$a2=array("c"=>"Cow","b"=>"Cat");

print_r(array_merge($a1,$a2));

12、将最后一个弹出

$a=array("Dog","Cat","Horse");

array_pop($a);

print_r($a);

13、计算数组中所有值得成绩

$a=array(5,5);

echo(array_product($a));

14、尾部追加

$a=array("Dog","Cat");

array_push($a,"Horse","Bird");

print_r($a);

15、随机取出n个数

$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");

print_r(array_rand($a,1));

16、将原数组翻转并返回新数组

$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");

print_r(array_reverse($a));

17、查找value返回key

$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");

echo array_search("Dog",$a);

18、删除第一个元素,并返回该元素

$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");

echo array_shift($a);

print_r ($a);

19、取出一段数组,起始位置,数量

$a=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird");

print_r(array_slice($a,1,2));

20、被删除数组,起始位置(正负代表从该值的位置正序还是倒叙),个数,从删除的位置插入的数组

$a1=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird");

$a2=array(0=>"Tiger",1=>"Lion");

print_r(array_splice($a1,0,2,$a2));//返回删除的值

print_r($a1);//$a1数组被修改了

21、计算所有值得和

$a=array(0=>"5",1=>"15",2=>"25");

echo array_sum($a);

22、删除数组中重复的值key

$a=array("a"=>"Cat","b"=>"Dog","c"=>"Cat");

print_r(array_unique($a));

23、从数组开头插入值

$a=array("a"=>"Cat","b"=>"Dog");

print_r(array_unshift($a,"Horse"));//返回插入后的数组个数

print_r($a);

24、数组排序,逆向排序rsort(),ksort() 对数组按照键名排序。

$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");

sort($my_array);

print_r($my_array);

25、数组长度,该函数是 count() 的别名。

$people = array("Peter", "Joe", "Glenn", "Cleveland");

$result = sizeof($people);

echo $result;

26、返回数组所有value,使用新key

$a=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");

print_r(array_values($a));

27、array_walk() 对数组中的每个成员应用用户函数。

28、将多个变量以键值对存入数组

$firstname = "Peter";

$lastname = "Griffin";

$age = "38";

$result = compact("firstname", "lastname", "age");

print_r($result);

29、指向数组末尾

$people = array("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "<br />";

echo end($people);

30、in_array() 检查数组中是否存在指定的值。

31、将数组的值赋值给变量

$my_array = array("Dog","Cat","Horse");

list($a, , $c) = $my_array;

echo "Here I only use the $a and $c variables.";

32、创建并返回一个包含指定范围的元素的数组。 最小值,最大值,步进

$number = range(0,5,2);

print_r ($number);

33、当前、上一个、下一个

$people = array("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "<br />";

echo next($people) . "<br />";

echo prev($people);

--------------------- 

作者:wz9666 

来源:CSDN 

原文:https://blog.csdn.net/edu_enth/article/details/55189646 

版权声明:本文为博主原创文章,转载请附上博文链接!


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post