Remove Something From an Array

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


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
Question by:edvinson
  • 2
  • 2
LVL 35

Accepted Solution

Raynard7 earned 500 total points
ID: 17792506

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){

Author Comment

ID: 17792520
A++++ as always, Raynard7.

Author Comment

ID: 17792543
Keep an eye out for for my next question in three minutes.... you can break the million point mark with it!!!
LVL 35

Expert Comment

ID: 17792567
Thanks, will look for it

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Update database from a form 8 35
File submission to SQL Server 1 39
<? versus <?php 5 37
How do I execute a file from within a PHP script with headers already sent? 5 21
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

910 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

24 Experts available now in Live!

Get 1:1 Help Now