SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    I want my 4th arrow! garlinto's Avatar
    Join Date
    Jun 2002
    Location
    Riding the electron wave
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Class method does NOT delete objects as intended

    In a newly constructed class, I have a method that I want to use to remove any item object where "0 == $item->qty". The item objects are held in an array of objects called "products":
    PHP Code:
    $this->products[$itemid
    Why will the method below NOT delete the item object with a quantity of zero?
    PHP Code:
    function removeInvalidItems ()
        {
           foreach ( 
    $this->products as $id)
           {
              if ( 
    == $id->qty )
              {
                  unset ( 
    $this->$id );
              }
           }
        } 
    Ducharme's Axiom: "If you view your problem closely
    enough, you will recognize yourself as part of the problem."


  2. #2
    SitePoint Addict
    Join Date
    May 2003
    Location
    Calgary, Alberta, Canada
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not positive about the answer without more code but this may be what youre looking for:
    PHP Code:
    function removeInvalidItems() {
        foreach(
    $this->products as $itemId => $product) {
            if (
    $product->qty == 0)    {
                unset(
    $this->products[$itemId]);
            }
        }


  3. #3
    I want my 4th arrow! garlinto's Avatar
    Join Date
    Jun 2002
    Location
    Riding the electron wave
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see my mistake.... worked great and as expected. Thank you
    Ducharme's Axiom: "If you view your problem closely
    enough, you will recognize yourself as part of the problem."



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
  •