Blogger Information
Blog 17
fans 0
comment 0
visits 12547
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组与数组函数学习心得
越努力越幸运
Original
1843 people have browsed it

//10个课堂未讲数组函数

     /*

     array_column

     array_rand();

     array_replace();

     array_intresect();

     array_diff();

     array_key_first();

     array_key_last();

     array_merge();

     array_chunk();

     next();

     */

    

     $arr5=[10=>1,5=>2,8=>3];

     $arr6=[3,5,7,10=>10];

    

     $obj1=array_rand($arr5);

     echo $obj1.'<br>';

    

     $arr7=array_replace($arr5, $arr6);

     var_dump($arr7);

     echo '<br>';

    

     $arr8=array_intersect($arr5, $arr6);

     var_dump($arr8);

     echo '<br>';

    

     $arr9=array_diff($arr5, $arr6);

     var_dump($arr9);

     echo '<br>';

    

     $obj2=array_key_first($arr5);

     echo $obj2.'<br>';

    

     $obj3=array_key_last($arr5);

     echo $obj3.'<br>';

    

     $arr10=array_merge($arr5,$arr6);

     var_dump($arr10);

     echo '<br>';

    

     $arr11=array_chunk($arr5,1);

     var_dump($arr11);

     echo '<br>';

    

     next($arr6);

     $obj4=current($arr6);

     echo $obj4.'<br>';

    

     $arr12=[

     0=>[

     'id'=>1,

     'name'=>'peter',

     'password'=>'123456'

     ],

     1=>[

     'id'=>2,

     'name'=>'frank',

     'password'=>'123'

     ],

     2=>[

     'id'=>3,

     'name'=>'jack',

     'password'=>'12345'

     ]

     ];

    

     $id=array_column($arr12,'id');

     $name=array_column($arr12,'name');

     $password=array_column($arr12,'password');

    

     var_dump($id);

     echo '<hr>';

     var_dump($name);

     echo '<hr>';

     var_dump($password);

     echo '<hr>';

//四个回调函数

     /*

     array_filter();//返回结果是true的元素

     array_map();//每个元素挨个拉出来function;

     array_reduce();//拉平不合理的二维数组,成为一维数组;

     array_walk();

     */

    

     $arr13=[1,2,3,4,5,6,''];

     $arr14=array_filter($arr13,function ($item){

     return $item;

     });

    

     var_dump($arr14);

     echo '<br>';

    

     $arr15=array_map(function ($item){

     if($item%2===0){

     return $item;

     }

    

     }, $arr13);

    

     var_dump($arr15);

     echo '<br>';

    

     $arr16=[

     0=>['id'=>1],

     1=>['name'=>'peter'],

     2=>['password'=>'123456']

     ];

    

     $arr17=array_reduce($arr16,function ($prev,$cc){

     $key=key($cc);

     $value=current($cc);

     $prev[$key]=$value;

     return $prev;

    

     });

    

     var_dump($arr17);

     echo '<br>';

    

     $arr18=[1,2,3,4,5,6];

    

     $arr19=array_walk($arr18, function ($item){

     if($item%2===0){

     return $item;

     }

     });

    

     var_dump($arr19);

     echo '<br>';

//array_slice();array_splice();


     $goods1=[

     'productno'=>'0001',

     'material'=>'AL',

     'size'=>'3inch'

     ];

    

     $material=array_slice($goods1,1,1);

    

     var_dump($material);

     echo '<br>';

    

     array_splice($goods1,1,1,'FE');

     var_dump($goods1);

     echo '<br>';


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