Removing a number of elements from an array - how?

Discussion in 'PHP' started by Kratylos, Jan 16, 2009.

  1. #1
    My apologies if this is a stupid question, but for some reason, I simply can't seem to come up with a fairly simple way to do this. I know it should be simple, but my brain doesn't seem to want to come up with a simple solution.

    The situation:
    I have a fairly large array (a few hundred items).

    I need to remove a number of elements from it (key numbers are probably contained in another array, gotten by exploding a string from a cookie).

    The result needs to be the large array, with sequential key numbers, minus the elements the keys of which were in the other array.

    Any thoughts?
     
    Kratylos, Jan 16, 2009 IP
  2. jack_ss

    jack_ss Guest

    Messages:
    94
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    unset($array[$key]); doesn't work?
     
    jack_ss, Jan 16, 2009 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    put the key numbers in a loop and unset them?
     
    ads2help, Jan 16, 2009 IP
  4. artiskool

    artiskool Peon

    Messages:
    34
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    As a common practice, if you remove an item/items make sure to check if that key exists, otherwise PHP throws WARNING that key does not exists.
     
    artiskool, Jan 16, 2009 IP