note 31683 added to function.array-slice
| From: | bh_bane at hotmail dot com | Date: | Wed, 30 Apr 2003 09:20:23 +0000 |
| Subject: | note 31683 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47280@lists.php.net to get a copy of this message | ||
j dot bailleul at free dot fr
22-Feb-2003 12:09
This is a fonction to remove one element. Combine array_slice and array_merge
// function remove_one_element($array,$index_to_remove){
// // $index_to_remove : type integer
// $index_nb_elements=count($array)-1;
// switch($index_to_remove){
// case 0:
// $array = array_slice($array, 1);
// break;
// case $index_nb_elements :
// $array = array_slice($array, -1);
// break;
// default:
// $array_start = array_slice($array,0, $index_to_remove);
// $array_end = array_slice($array, $index_to_remove+1);
// $array = array_merge ($array_start, $array_end);
// break;
// }
// return $array;
// }
shouldn´t it be
case $index_nb_elements :
$array = array_slice($array, 0,-1);
break;
to makes sence ? ;)
best regards Benjamin
--
http://www.php.net/manual/en/function.array-slice.php
http://master.php.net/manage/user-notes.php?action=edit+31683
http://master.php.net/manage/user-notes.php?action=delete+31683
http://master.php.net/manage/user-notes.php?action=reject+31683