Solved

Remove Something From an Array

Posted on 2006-10-23
4
183 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

820 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