PHP二维数组排序

<?php

/*     查找       */
$Country=array("China","Canada","Italy","UK","USA");
$str="America";
if(in_array($str,$Country)){
echo "right";
}
else{
echo "no";
}

/* 判断是否为数组,是则输出元素个数  */

if(is_array($Country)){
echo "yes".count($Country);
}
else{
echo "no";
}

echo "<br/>";

/*    遍历元素    */

for($i=0;$i<=count($Country)-1;$i++){
echo ($i+1).".".$Country[$i]."<br/>";
}

echo "<br/>";

$i=0;
while($i<=count($Country)-1){
echo ($i+1).".".$Country[$i]."<br/>";
$i++;
}

echo "<br/>";

while(list($key,$value)=each($Country)){
echo "$key.$value"."<br/>";
}

echo "<br/>";

/*   后补一个元素     */

array_push($Country,"Germany");
$i=0;
while($i<=count($Country)-1){
echo ($i+1).".".$Country[$i]."<br/>";
$i++;
}

echo "<br/>";

/*   前补一个元素     */

array_unshift($Country,"Swiss");

$i=0;
while($i<=count($Country)-1){
echo ($i+1).".".$Country[$i]."<br/>";
$i++;
}

echo "<br/>";

/*   删除最后一个元素    */

array_pop($Country);

$i=0;
while($i<=count($Country)-1){
echo ($i+1).".".$Country[$i]."<br/>";
$i++;
}

echo "<br/>";

/* 删除第一个元素 */

array_shift($Country);
$i=0;
while($i<=count($Country)-1){
echo ($i+1).".".$Country[$i]."<br/>";
$i++;
}

echo "<br/>";

/* 排序 */

sort($Country);
$i=0;
while($i<=count($Country)-1){
echo ($i+1).".".$Country[$i]."<br/>";
$i++;
}

echo "<br/>";
/* 合并数组 */

$province=array("henan","shanghai","washingdon","newyork");
$newarray=array_merge($Country,$province);
$i=0;
while($i<=count($newarray)-1){
echo ($i+1).".".$newarray[$i]."<br/>";
$i++;
}
?>

    A+
发布日期:2009年02月13日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: