Blogger Information
Blog 3
fans 0
comment 0
visits 1290
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
[0812] 5种数组函数
P粉912642467
Original
352 people have browsed it

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));
Correcting teacher:PHPzPHPz

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