unset range of keys in an array

前端 未结 2 929
我在风中等你
我在风中等你 2021-01-19 18:10

How can i unset a range of keys between say 70 to 80 in an array like this?

[63] => Computer Science and Informatics
[64] => Dentistry
[65] => Devel         


        
相关标签:
2条回答
  • 2021-01-19 18:23

    You can try array_slice

    $return = array_slice($original, 0, 60)
    

    then

    $return = $return+array_slice($original, 70)
    

    or

    array_splice

    $return = array_splice($original, 60, 10)
    
    0 讨论(0)
  • 2021-01-19 18:37

    There isn't really a shortcut to this:

    for ($i = 70; $i <= 80; $i++)  
        unset($array[$i]);
    
    0 讨论(0)
提交回复
热议问题