首页 > 代码库 > php -- 数组
php -- 数组
----- 021-array.php -----
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5 <title>Array</title> 6 </head> 7 <body> 8 <h2>Array</h2> 9 <pre style="font-size:10pt"> 10 <?php 11 $sheeps["灰太狼爱吃"] = "喜羊羊"; 12 $sheeps["邋遢大王爱吃"] = "美羊羊"; 13 $sheeps["熊大爱吃"] = "懒羊羊"; 14 $sheeps["葫芦娃爱吃"] = "喜羊羊"; 15 $sheeps["熊二爱吃"] = "美羊羊"; 16 $sheeps["红太狼爱吃"] = "懒羊羊"; 17 echo "\$是否为数组?", is_array($sheeps), "\n"; 18 echo "是否包含喜羊羊?", in_array("喜羊羊", $sheeps), "\n"; 19 echo "谁爱吃喜羊羊:", var_export(array_keys($sheeps, "喜羊羊")), "\n"; 20 echo "有多少羊?", var_export(array_values($sheeps)), "\n"; 21 echo "有没有邋遢大王爱吃的羊?", array_key_exists("邋遢大王爱吃", $sheeps), "\n"; 22 echo "懒羊羊谁爱吃?", array_search("懒羊羊", $sheeps), "\n"; 23 24 array_push($sheeps, "沸羊羊"); 25 array_unshift($sheeps, "慢羊羊"); 26 echo "加上俩:", var_export($sheeps), "\n"; 27 echo "填充到10个:", var_export(array_pad($sheeps, -10, "无名之羊")), "\n"; 28 echo "去重后:", var_export(array_unique($sheeps)), "\n"; 29 $temp = $sheeps; 30 sort($temp); 31 echo "排序后:", var_export($temp), "\n"; 32 echo "哪只最好吃?", var_export(array_count_values($sheeps)), "\n"; 33 //error_reporting(0);//不报告错误 34 echo "当前时间", date("Y年m月d日H时i分s秒", time()+28800),"\n"; 35 ?> 36 </pre> 37 </body> 38 </html>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。