欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

有趣的几个数组函数

程序员文章站 2024-02-24 17:52:04
...
<?php
$a=array("This","is","just","a","test");
echo implode(" ",$a)."<br>";//将数组$a内的元素以空格为间隔,转为字符串,并输出
echo count($a)."<br>";//获取数组长度
if(in_array("just",$a))//查找指定的字符或者字符串是否在指定数组内,是则返回true
 echo "The word 'just' is in this array."."<br>";
else echo "The word 'just' isn't in this array."."<br>";
//有趣的array_search()
$fruits["aoole"]="red";
$fruits["watermelon"]="green";
$founded=array_search("green",$fruits);//返回对应的键值
if($founded)
 printf("%s was founded on %s",$founded,$fruits[$founded]);
?>

结果如下:

This is just a test
5
The word 'just' is in this array.
watermelon was founded on green