博主信息
博文 3
粉丝 0
评论 0
访问量 2501
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
[0812] 5种数组函数
P粉912642467
原创
522人浏览过

array_chuck()

  1. $stu = [
  2. 'id' => 101,
  3. 'name' => '无忌',
  4. 'age' => 20,
  5. 'course' => 'php',
  6. 'grade' => 80
  7. ];
  8. $fn1 = array_chunk($stu,2);
  9. printf("<pre>%s</pre>",print_r($fn1,true));
  10. foreach($fn1 as $singleStudent){
  11. foreach($singleStudent as $detail){
  12. echo $detail."<br>";
  13. }
  14. }
  15. echo "<hr>";

array_combine()

  1. $number = ['1','2','3'];
  2. $student = ['Steve','Carl','Jessica'];
  3. $newClass = array_combine($number,$student);
  4. foreach($newClass as $key=>$singleStudent){
  5. printf('[ %s ] => %s<br>', $key, $singleStudent);
  6. }
  7. echo "<hr>";

array_map()

  1. $number2 = ['4','5','6'];
  2. function doubleNum($num){
  3. return $num *2;
  4. }
  5. $afterMap = array_map('doubleNum',$number2);
  6. foreach ($afterMap as $singleNum) {
  7. echo $singleNum."<br>";
  8. }

echo “<hr>“;

array_merge()

  1. $student2 = ['Leo','Jeff','Dean'];
  2. $studentGroup = array_merge($student, $student2);
  3. foreach($studentGroup as $singleStudent){
  4. echo $singleStudent."<br>";
  5. }
  6. echo "<hr>";

array_walk()

  1. $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
  2. ksort($fruits);
  3. function addFruit($putInFruit, $key){
  4. echo $key.":".$putInFruit."<br>";
  5. }
  6. array_walk($fruits,'addFruit');
  7. // printf("<pre>%s</pre>",print_r($newFruits,true));
批改老师:PHPzPHPz

批改状态:合格

老师批语:用课堂未演示的数组函数
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学