Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove Something From an Array

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.
Suggested Courses

782 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