delete multiple specific array values

Discussion in 'PHP' started by Shimurai, Jan 21, 2012.

  1. #1
    Hi,

    I'm trying to do an album system and need some help with arrays.

    I have a table in my database called albums and in there I have two columns: album_id & album_images.

    album_id is set to be INT with auto-increment, and inside album_images is where I add all the images that will be inside the "album".

    the data inside the album_images row would look like this:
    KZ84U.png||RTqbB.jpg||0xk5B.png||qiof.jpg||TAtJa.png||lvkwY.jpg||kEejG.jpg||7hEt.jpg||oUreT.jpg||i1IA.jpg||JNYQp.jpg||8C5D.jpg
    Code (markup):
    so then I can use explode function and separate each image name and display in a page.

    I am having trouble adding and removing single/multiple images from the array generated with the explode function.

    so basically what I want to be able to do is, if for example I want to remove image "lvkwY.jpg" the album_images row will be updated without including the image i removed from the album, same with multiple images.

    also when I want to add new images, how can I check if an image I am trying to add is already in the array ??

    I would appreciate any help with this, I really have no clue how I can do this.

    Thanks !
     
    Shimurai, Jan 21, 2012 IP
  2. trtrtrtr

    trtrtrtr Greenhorn

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    
    $album_images = explode ("|",$album_images);
    foreach($album_images  as $key=>$value){
    if ($value == $ToBeDeleteImage) unset $album[$key];
    }
    
    Code (markup):
     
    trtrtrtr, Jan 21, 2012 IP