<?php

$arr1 = array(1,3, 5,7,8);

$key = array_search(3, $arr1);

if ($key !== false){

  array_splice($arr1, $key, 1);

}

var_dump($arr1);

// array(4) { [0]=> int(1) [1]=> int(5) [2]=> int(7) [3]=> int(8) }

?>

 

<?php

 

$arr2 = array(1,3, 5,7,8);

 

foreach ($arr2 as $key=>$value)

 

{

 

  if ($value === 3){

 

    unset($arr2[$key]);

 

  }

 

}

 

var_dump($arr2);

 

// array(4) { [0]=> int(1) [2]=> int(5) [3]=> int(7) [4]=> int(8) }

 

?>

 

posted on 2017-06-26 11:53  啥也不会的程序猿  阅读(2807)  评论(0编辑  收藏  举报