Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Deleting array index, how?

    Hi,

    I have an array:

    $sentences = array("1","2","3","4");

    How can I delete an index or indexes? I don't want to leave empty stringed array indexes...

    Thank you!
    PHP 5 & MySQL 5 (Y)

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    This:

    // Now delete every item, but leave the array itself intact:
    foreach ($sentences as $i => $value) {
    unset($sentences[$i]);
    }

    Comes from this site:
    http://us2.php.net/types.array


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •