Solved

Remove Something From an Array

Posted on 2006-10-23
4
180 Views
Last Modified: 2006-11-18
I am writing a class, that so far looks like this:

( The user is building a custom door )....


Anyways, I want a method to remove from the "KIT" a certain part number, like:

$myDoor->removePartFromKit("353325");  // the part number to remove

So how do I find the part number and remove it from my "KIT" array?

THanks!



class newDoor {

      var $door_type;
      var $kit;
      
      function AddPartToKit($p, $d, $pr){
            
            $this->kit[] = array("PartNumber" => $p, "Desc" => $d, "Price"  => $pr)      ;      
            
      }
      
      
      // Set Door Type
      function SetDoorType($dType) {
      
            $this->door_type = $dType;
      
      }

} // End Class
0
Comment
Question by:edvinson
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 total points
Comment Utility
Hi,

You want something like below - this should go through everything in the kit array and retreive its key if the part number is the same as the part number submitted to the function
It then removes all the rows from the kit array where the part number was found (if any)

     function RemoveFromKit($KitPartNumber){
          foreach($this->kit as $key=>$value){
                if ($value['PartNumber'] == $KitPartNumber){
                    $arrayToRemove[] = $key;
                }
          }
          if (isset($arrayToRemove)) {
                foreach($arrayToRemove as $key=>$value){
                    unset($this->kit[$value]);
                }
          }
     }
0
 
LVL 1

Author Comment

by:edvinson
Comment Utility
A++++ as always, Raynard7.
0
 
LVL 1

Author Comment

by:edvinson
Comment Utility
Keep an eye out for for my next question in three minutes.... you can break the million point mark with it!!!
0
 
LVL 35

Expert Comment

by:Raynard7
Comment Utility
Thanks, will look for it
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now