SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast stationmaster's Avatar
    Join Date
    May 2003
    Location
    barcelona
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how do you: Remove an array from multiarray with a value?

    I need to remove an array from a multiarray,
    I have the key (ID) $post->ID, and the value (811) $thispost_id from an independent array, $post.
    my second array id $posts.

    PHP Code:
               /*
               global $post;
               $thispost_id = $post->ID;
                          
               $posts is an array starting like this:
               array(4) { [0]=>  object(stdClass)#108 (24) { ["ID"]=>  string(3) "821" ... }
                          [1]=>  object(stdClass)#107 (24) { ["ID"]=>  string(3) "817" ... }
                          [2]=>  object(stdClass)#110 (24) { ["ID"]=>  string(3) "811" ... }
                          [3]=>  object(stdClass)#109 (24) { ["ID"]=>  string(3) "807" ... }*/
               
               /* I need to pop the array with $thispost_id out of $posts*/ 
    I've done my search, and done my studies, but I'm needing some help with this one.
    TIA for any pointers.
    Daiv Mowbray twincascos Barcelona
    wordpress pluginswp-superslider.com
    portfolio portfolio.daivmowbray.com
    personal blogwww.daivmowbray.com

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    foreach ($posts as $key => $obj) {
      if (
    $obj->ID == $thispost_id)
        unset(
    $posts[$key]);


  3. #3
    SitePoint Enthusiast stationmaster's Avatar
    Join Date
    May 2003
    Location
    barcelona
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, that was fast,
    Thanx you Dan!
    Yes that is the how, unset was the trick


Bookmarks

Posting Permissions

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