Blogger Information
Blog 33
fans 0
comment 0
visits 20721
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php基础-数组相关函数操作2018年8月24日
马聪 15558002279的博客
Original
460 people have browsed it
  1. 作业代码:


  2. 实例

    <?php
    //创建一个数组
    $list = [1,2,3,2,5,2,66,32,33,66,2,3,6,2,3];
    $arr=array();
    $i =1;
    foreach (range("a","z") as $k){
        $arr[$k] = $i;
        $i++;
    }
    
    
    //数组=>字符串转换
    $str = implode($list,"|");
    //string '1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26'
    
    
    //字符串转数组
    $list = explode("|",$str);
    
    
    //数组=>变量
    array_walk($arr,function ($v,$k){
        echo "键为",$k," => ","值为",$v,"<br>";
    });
    list($a,$b,$c) = $list;
    echo $a,$b,$c;
    
    
    //变量=>数组
    $list = compact('a','b','c');
    
    
    //数组元素的回调处理,返回奇数
    $res = array_filter($arr,function ($v){
        return $v%2;
    });
    var_dump($arr);
    for ($i=0;$i<=count($arr);$i++){
        $i=$i?:1;
        $arr_key = array_search($i,$arr);
        echo $arr_key."=>".$arr[$arr_key];
    }
    ?>

    运行实例 »

    点击 "运行实例" 按钮查看在线实例

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post