RE: [PHP] Removing an element from the middle of an mdlti-dimentsional array

From: Date: Fri, 15 Aug 2008 15:51:52 +0000
Subject: RE: [PHP] Removing an element from the middle of an mdlti-dimentsional array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-278147@lists.php.net to get a copy of this message
> -----Original Message----- > From: Simcha Younger [mailto:simcha.younger@gmail.com] > Sent: Friday, August 15, 2008 2:49 AM > To: 'Don'; php-general@lists.php.net > Subject: RE: [PHP] Removing an element from the middle of an mdlti- > dimentsional array > > > array_splice($a, 1, 1); > > This will remove the second element, and reset the keys. > > > -----Original Message----- > From: Don [mailto:don@program-it.ca] > Sent: Friday, August 15, 2008 4:30 AM > To: php-general@lists.php.net > Subject: [PHP] Removing an element from the middle of an mdlti- > dimentsional > array > > Hi, > > Let's say I have the following array: > > $myArray = array(array('1','2','3'), > array('4','5','6'), > array('7','8','9'), > > array('10','11','12')); > > How do I remove say the second element? > > I have tried: $myArray = array_splice($myArray, 1, 1); > > But this seems to remove the second element as well as all the > following > elements and I am left with: > > $myArray = array(array('1','2','3')); > > when I really want: > > $myArray = array(array('1','2','3'), > array('7','8','9'), > array('10','11','12')); Yep. He had been using the return value of array_splice(), which is just the spliced elements--not the resulting array post-splice. http://www.php.net/array_splice Todd Boyd Web Programmer

« previous php.general (#278147) next »