note 104983 modified in function.array-splice by danbrown

From: Date: Thu, 21 Jul 2011 16:01:19 +0000
Subject: note 104983 modified in function.array-splice by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181761@lists.php.net to get a copy of this message
Sometimes you may want to insert one array into another and just work on with the resulting array. array_splice() doesn't support this, as the resulting array isn't the returned value but the first argument, which is changed by reference. Therefore you may use the following function, which inserts array $ins in array $src at position $pos. $rep can be used if $ins shouldn't be just inserted, but should replace some existing elements (the number of elements to be replaced is given in $rep). <?php function array_insert($src,$ins,$pos,$rep=0) { array_splice($src,$pos,$rep,$ins); return($src); } ?> --was-- Sometimes you may want to insert one array into another and just work on with the resulting array. array_splice() doesn't support this, as the resulting array isn't the returned value but the first argument, which is changed by reference. Therefore you may use the following function, which inserts array $ins in array $src at position $pos. $rep can be used if $ins shouldn't be just inserted, but should replace some existing elements (the number of elements to be replaced is given in $rep). function array_insert($src,$ins,$pos,$rep=0) { array_splice($src,$pos,$rep,$ins); return($src); } http://php.net/manual/en/function.array-splice.php

« previous php.notes (#181761) next »