note 35299 added to function.array-splice

From: Date: Tue, 26 Aug 2003 19:51:56 +0000
Subject: note 35299 added to function.array-splice
Groups: php.notes 
Request: Send a blank email to php-notes+get-55138@lists.php.net to get a copy of this message
Just fenced the infamous problem of the Associative Arrays v/s array_splice. I've done this little function to get around it. It seems to work pretty well, by I'm kind of a novice in this so I'm sure you'll find bugs, or better ways to do it: function ass_array_splice ( $in_arr, $desp, $size, $sust, $new_key='') { $head=array_slice($in_arr,0,$desp); $tale=array_slice($in_arr,$desp+$size); if ($new_key!='') $arr_res=array_merge($head, array($new_key=>$sust), $tale); else $arr_res=array_merge( $head, $sust, $tale); return $arr_res; } that's it. You call it like this: $P=ass_array_splice($_P, 18, 3, $P['FechD'].'/'.$P['FechM'].'/'.$P['FechA'],'Fech'); this example merges three cells from the array, and replace themselves with the result, calling the new cell 'Fech'. If you omit the last param, it calls the cel '0', just like old array_splice does. thanks for any feedback! ---- Manual Page -- http://www.php.net/manual/en/function.array-splice.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35299 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35299&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35299&report=yes

« previous php.notes (#55138) next »