php函数详解,php部分函数详解

本文主要和大家分享php部分函数详解,主要以代码的方式和大家分享,希望能帮助到大家。

1、array_diff_assoc($arr1,$arr2,$arr3...) 函数:比较两个数组的键名和键值,并返回差集

例:<?php

$a1=array("2"=>"this_2","3"=>"this_3","4"=>"this_4","5"=>"this_5");

$a2=array("1"=>"this_1","2"=>"this_2","3"=>"this_3");

$result1 = array_diff_assoc($a1,$a2); //数组可以交换顺序滴,也可以是多个数组

var_dump($result1);

?>

打印结果:array (size=2)

4 => string 'this_4' (length=6)

5 => string 'this_5' (length=6)

2、array_keys() 函数:返回包含数组中所有键名的一个新数组

例:<?php

$a1=array("2"=>"this_2","3"=>"this_3","4"=>"this_4","5"=>"this_5");

$result2 = array_keys($a1);

var_dump($result2);

?>

打印结果:array (size=4)

0 => int 2

1 => int 3

2 => int 4

3 => int 5

3、array_key_exists() 函数:检查某个数组中是否存在指定的键名,如果键名存在则返回 true,如果键名不存在则返回 false。

例:<?php

$a1=array("2"=>"this_2","3"=>"this_3","4"=>"this_4","5"=>"this_5");

if (key_exists("2",$a1)){

echo "yes!";

}else{

echo "no!";

}

?>

输出结果:yes!

4、sort() 函数:以升序对数组排序

5、rsort() 函数:以降序对数组排序

6、asort() 函数:根据值,以升序对关联数组进行排序

7、ksort() 函数:根据键,以升序对关联数组进行排序

8、arsort() 函数:根据值,以降序对关联数组进行排序

9、krsort() 函数:根据键,以降序对关联数组进行排序

10、count() 函数:返回数组中元素的数目

例:<?php

$a1=array("2"=>"this_2","3"=>"this_3","4"=>"this_4","5"=>"this_5");

$result3 = count($a1);

echo $result3;

?>

输出结果:4

相关推荐:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值