• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php部分函数详解

php 搞代码 4年前 (2022-01-22) 20次浏览 已收录 0个评论

本文主要和大家分享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!";}<p>+本文来源gao!%daima.com搞$代*!码9网(</p><strong>搞gaodaima代码</strong>?>

输出结果:

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

相关推荐:

php函数进阶讲解

PHP函数实例简介

php函数的查找性能测试

以上就是php部分函数详解的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php部分函数详解

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址