note 35299 deleted from function.array-splice by felipe
| From: | felipe@php.net | Date: | Sat, 05 Jan 2008 02:08:18 +0000 |
| Subject: | note 35299 deleted from function.array-splice by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134814@lists.php.net to get a copy of this message | ||
Note Submitter: Juan Guillermo Fernández
----
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:
<?php
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:
<?php
$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!