標籤:style class blog c code java
----- 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 <?php11 $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>