Re: Delete from Multidimensional Array?

From: Date: Tue, 03 Jun 2003 13:32:08 +0000
Subject: Re: Delete from Multidimensional Array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-149959@lists.php.net to get a copy of this message
> I've built a page that collects network card information, assigning each > element its place within a $Card array, and all of the cards to $NetCards. > As you enter your card information at the bottom, the previous card is > displayed above it, with a Delete checkbox option at the end of that row > ($Delete[$Card]). > > But I can't figure out how to actually delete that card from the "deck", > as it were. I've looked over the Arrays pages, but there's little there > about multi-dimensional arrays and I ended up more confused than ever. > Here's my print_r: > > Array <=--- This is $NetCards > ( > [0] => Array <=--- This one is just > $Card > ( > [0] => 3Com <=--- Description > [1] => 12:34:45:78:90:AA <=--- MAC Address > [2] => 129.93.100.100 <=--- IP Address > ) > > [1] => Array > ( > [0] => Intel 100b > [1] => 12:34:45:78:90:AB > [2] => 129.93.100.101 > ) > > [2] => Array > ( > [0] => ThinAire > [1] => 12:34:45:78:90:BB > [2] => 129.93.100.102 > ) > > [3] => Array > ( > [0] => 3Com > [1] => 12:34:45:78:90:BC > [2] => 129.93.100.103 > ) > > ) > > How can I delete, say, the wireless card (ThinAire) which is third, here, > if someone clicks on that one's Delete box? Thanks! Assuming you somehow already get the "2" value when the user checks the checkbox, you'd simply call unset($NetCards[2]); to get rid of the "ThinAire" card. If you're also looking for help making the checkboxes, let me know. ---John Holmes...

« previous php.general (#149959) next »