Home > Backend Development > PHP Tutorial > php array_push function to add value to array_PHP tutorial

php array_push function to add value to array_PHP tutorial

WBOY
Release: 2016-07-20 11:06:46
Original
1943 people have browsed it

php  array_push 向数组增加值函数
 public static function insert(&$array, $key, $newValue, $before = true) {
  $result = false;
  $size = sizeof($array);
  for ($i=0; $i<$size; $i++) {
   $value = array_shift($array);
   if ($i==$key) {
    if ($before) {
     array_push($array, $newValue);
     array_push($array, $value);
    } else {
     array_push($array, $value);
     array_push($array, $newValue);
    }
    $result = true;
   } else {
    array_push($array, $value);
   }
  }
  if (!$result) {
   array_push($array, $newValue);
  }
  return;
 }


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445009.htmlTechArticlephp array_push 向数组增加值函数 public static function insert($array, $key, $newValue, $before = true) { $result = false; $size = sizeof($array); for ($i=0; $i$size; $i++)...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template