Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Remove Something From an Array

Posted on 2006-10-23
4
Medium Priority
?
187 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

721 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