note 35299 modified in function.array-splice by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:49:43 +0000 |
| Subject: | note 35299 modified in function.array-splice by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80074@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:
<?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!
--was--
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!
http://php.net/manual/en/function.array-splice.php