Solved

Remove Something From an Array

Posted on 2006-10-23
4
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 total points
ID: 17792506
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
ID: 17792520
A++++ as always, Raynard7.
0
 
LVL 1

Author Comment

by:edvinson
ID: 17792543
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
ID: 17792567
Thanks, will look for it
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

752 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