Blogger Information
Blog 23
fans 0
comment 0
visits 18917
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
将数组中的值取出并重新排序
手机用户1617360551
Original
592 people have browsed it

取出数组中的值并重置索引

  • 用array_values数组函数

  1. <?php
  2. $arr = [ 4 => 10, 1 => 22, 9 => 55, 0=>255];
  3. $res = array_values($arr);
  4. printf('<pre>%s</pre>',print_r($res,true));
  • 数组遍历的方式

  1. <?php
  2. $arr1 = [ 4 => 10, 1 => 22, 9 => 55, 0=>255];
  3. $res1 = [];
  4. foreach($arr1 as $k => $v)
  5. {
  6. array_push($res1,$v);
  7. }
  8. echo '<pre>';
  9. print_r($res1);
  • 头部移除数组单元的

  1. <?php
  2. $arr2 = [ 4 => 10, 1 => 22, 9 => 55, 0=>255];
  3. $res2[] = array_shift($arr2);
  4. $res2[] .= array_shift($arr2,);
  5. $res2[] .= array_shift($arr2,);
  6. $res2[] .= array_shift($arr2,);
  7. echo '<pre>';
  8. print_r($res2);
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