Search and delete

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • InSeCo

    Search and delete

    Hello,

    how can I delete a part from an array?

    I want to search in the array to the first 5 characters, after that I want
    to delete the value from the array!

    ## Before
    $example = array(
    1 => '1001,sastu',
    2 => '1003,dudaa',
    3 => '1006,s1001fd',
    4 => '1008,empdat',
    5 => "1010,limaa d",
    );

    ##after searching for "1006," the record must be deleted!
    $example = array(
    1 => '1001,sastu',
    2 => '1003,dudaa',
    4 => '1008,empdat',
    5 => "1010,limaa d",
    );

    Thnx,
    InseCo








  • DJ Craig

    #2
    Re: Search and delete

    function array_remove($a , $n){
    $new = array_merge(arr ay_slice($a, 0, $n), array_slice($a, $n + 1));
    }

    Comment

    • DJ Craig

      #3
      Re: Search and delete

      Correction:

      function array_remove($a , $n){
      return array_merge(arr ay_slice($a, 0, $n), array_slice($a, $n + 1));
      }

      Comment

      • BKDotCom

        #4
        Re: Search and delete

        Is your array really indexed beggining with 1?
        do you really need the keys reindexed?
        why won't a simple unset($example[3]) do?

        Comment

        Working...