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

php array_push function to add value to array_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:06:461913browse

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++)...
Statement:
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