php2

$arr = array("a","hello","c",10);
echo $arr[1].PHP_EOL;//输入字符的坐标,输出相应位置的字符
$arr[] = 2;//把2添加到数组的最后[]里可定位存放位置
var_dump($arr).PHP_EOL;


//key   value
//name:youyong
//age:23
//like:xiaqi
//sex:nan


$arr = array("name"=>"youyong","age"=>23,"like"=>"xiaqi");//name对应youyong
var_dump($arr);
echo $arr["name"];
$arr["sex"]="nam";//添加一个sex位置上的值为nan


$arr1=array("1999-3-3","2019-12-10","2019-12-11");
$arr2=array("shengri"=>"1999-3-3","shuang11"=>"2019-11-11","shang12"=>"2019-12-12");
$arr2["yuandan"]="2020-1-1";
var_dump($arr1).PHP_EOL;
var_dump($arr2).PHP_EOL;


$arr= array(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0);
for ($i=0;$i<count($arr);$i++){
    echo $arr[$i].PHP_EOL;
}


$arr = array("name"=>"youyong","age"=>23,"like"=>"xiaqi");//name对应youyong
$arr["sex"]="nam";//添加一个sex位置上的值为nan


foreach ($arr as $k=>$v){   //有key的数组需要用foreach循环   $k : key  $v : value
    echo $k.":".$v.PHP_EOL;
}

$arr1=array("name"=>"youyong","age"=>23,"like"=>"xiaqi");
$arr2=array("name"=>"youyong","age"=>23,"like"=>"xiaqi");
$arr3=array("name"=>"youyong","age"=>23,"like"=>"xiaqi");
$arr4=array($arr1,$arr2,$arr3);
//var_dump($arr4);

//var_dump($arr4[1]["age"]);//取$arr2的age的值

for ($i=0;$i<count($arr4);$i++){
    foreach ($arr4[$i] as $k=>$v){
        echo $k.":".$v.PHP_EOL;
    }
}


$arr1=array(1,2,3);
$arr2=array(1,2,3);
$arr3=array(1,2,3);
$arr4=array($arr1,$arr2,$arr3);
for ($i=0;$i<count($arr4);$i++){
    for ($j=0;$j<count($arr4[$i]);$j++){
//        var_dump($arr4[$i][$j]);
        echo $arr4[$i][$j].PHP_EOL;
    }
}


$a=array(80,60,70);
$b=array(80,60,70);
$c=array(80,60,70);
$d=array("lisi"=>$a,"wangwu"=>$b,"zhangsan"=>$c);
foreach ($d as $k=>$v){
    for ($i=0;$i<count($d[$k]);$i++){
//        var_dump($d[$k][$i]);
        echo $d[$k][$i].PHP_EOL;
    }
}

$a=array("name"=>"lisi","age"=>23,"sex"=>"nan");
$b=array("name"=>"wangwu","age"=>23,"sex"=>"nan");
$c=array("name"=>"zhangsan","age"=>23,"sex"=>"nan");
$d=array("lisi"=>$a, "wangwu"=>$b, "zhangsan"=>$c);
foreach ($d as $k=>$v){
    foreach ($d[$k] as $l=>$m){
//        var_dump($d[$k][$l]);
        echo $d[$k][$l].PHP_EOL;
    }
}

$arr=array("asd","qwe","zxc","rty");
while ($a=each($arr)){      //each 每次执行拿出一个坐标和一个值
        var_dump($a);
}

$arr=array("asd","qwe","zxc","rty");    //把$arr的每一个元素赋值给一个变量
list($a,$b,$c,$d)=$arr;
echo $a.PHP_EOL;
echo $b.PHP_EOL;
echo $c.PHP_EOL;
echo $d.PHP_EOL;

$num=456;
$a1=str_split($num);        //把$num拆分成3个数组
list($a,$b,$c)=$a1;
echo $a.PHP_EOL;
echo $b.PHP_EOL;
echo $c.PHP_EOL;

$num=456;
$a=str_split($num);
$b=array_reverse($a);   //把$num翻转(倒序)
var_dump($b);

$arr = [7,54,76541,754,23,456,64,1];//快速排序
sort($arr);
var_dump($arr);

$arr = [7,54,76541,754,23,456,64,1];
rsort($arr);//反向排序
var_dump($arr);

$arr=array(1,2,3,4,5,6,7,8,9,0,3,5,3,2,3,5,2,1,4);
var_dump(array_count_values($arr));//每个元素出现了几次   关联数组

$arr=array(1,2,3,4);
var_dump(array_pad($arr,7,0));//在后面追加三个0
var_dump(array_pad($arr,-7,0));//在前面追加三个0

$a=1;
echo $a;
unset($a);//删除变量$a
echo $a;
$arr=array(1,2,3);
var_dump($arr);
unset($arr[0]);//删除第一个元素
var_dump($arr);

$arr=array_fill(3,10,"abc");//从第3位开始创建10个数组“abc”
var_dump($arr);

$arr = ["a","b","c"];
$arr1=["aa","bb","cc"];
$arr2=array_combine($arr,$arr1);//把两个数组合并成一个新数组,一个数组位键值,一个为元素
var_dump($arr2);

$arr = ["a","b","c","d","e","f"];
array_splice($arr,2,2,["a","b","c"]);
//在$arr里从2(坐标)开始删除两个  并替换一个数组(把“删除两个换成删除0个”可以变为插入)
var_dump($arr);

$arr = ["a","b","c","a","b","c"];
var_dump(array_unique($arr));//去重

$arr = ["a","b","c"];
$arr1=["aa","bb","cc"];
$arr2=array_combine($arr,$arr1);
var_dump($arr2);
$arr3=array_flip($arr2);//键值与元素互换
var_dump($arr3);

$arr = ["a","b","c","a","b","c"];
var_dump(array_search("c",$arr));
//返回“c”第一次出现的位置   没有该元素返回float

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值