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. Simcha Younger -Original Message- From: Don [mailto:[EMAIL PROTECTED] 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')); Thanks, Don -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.138 / Virus Database: 270.6.3/1612 - Release Date: 14/08/2008 18:03 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Removing an element from the middle of an mdlti-dimentsional array
-Original Message- From: Simcha Younger [mailto:[EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Removing an element from the middle of an mdlti-dimentsional array
Can't you unset() it? Sorry for top posting I'm on an iPhone On Aug 14, 2008, at 7:30 PM, Don [EMAIL PROTECTED] wrote: 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')); Thanks, Don -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Removing an element from the middle of an mdlti-dimentsional array
Won't unset() destroy the entire array? mike [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Can't you unset() it? Sorry for top posting I'm on an iPhone On Aug 14, 2008, at 7:30 PM, Don [EMAIL PROTECTED] wrote: 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')); Thanks, Don -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Removing an element from the middle of an mdlti-dimentsional array
Not on the specific sub element. I.e unset($array[2][0]) On Aug 14, 2008, at 8:08 PM, Don [EMAIL PROTECTED] wrote: Won't unset() destroy the entire array? mike [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Can't you unset() it? Sorry for top posting I'm on an iPhone On Aug 14, 2008, at 7:30 PM, Don [EMAIL PROTECTED] wrote: 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')); Thanks, Don -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Removing an element from the middle of an mdlti-dimentsional array
Yup, thanks. Also execute: $array = array_values(array) in order to fix the indexes - Original Message - From: mike [EMAIL PROTECTED] To: Don [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Thursday, August 14, 2008 11:16 PM Subject: Re: [PHP] Removing an element from the middle of an mdlti-dimentsional array Not on the specific sub element. I.e unset($array[2][0]) On Aug 14, 2008, at 8:08 PM, Don [EMAIL PROTECTED] wrote: Won't unset() destroy the entire array? mike [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Can't you unset() it? Sorry for top posting I'm on an iPhone On Aug 14, 2008, at 7:30 PM, Don [EMAIL PROTECTED] wrote: 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')); Thanks, Don -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.138 / Virus Database: 270.6.3/1611 - Release Date: 8/14/2008 6:20 AM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php