How to remove only item of array?

This question already has an answer here:

  • PHP: Delete an element from an array 34 answers

  • try this

    $a_input = array(1,2,3,4,5);
    
    $cnt=count($a_input);
    for($i=0;$i<$cnt;$i++){
       $remove = array($i+1);
       $output1=array_diff($a_input,$remove);
       var_dump("<pre>",$output1);
    }
    

    Online test


    使用未unset

    foreach($a_input as $key => $val){
       if($a_input[$key]==1) unset($a_input[$key]); 
    }
    

    您可以使用

    $array = array(1,2,3,4,5);
    if (($key = array_search('1', $array)) !== false) {
    unset($array[$key]);
    }
    
    链接地址: http://www.djcxy.com/p/30114.html

    上一篇: 删除数组中的第一个结果

    下一篇: 如何只删除数组的项目?