/**
* Copies an array from the specified source array, beginning at the specified position,
* to the specified position of the destination array. A subsequence of array components are
* copied from the source array referenced by src to the destination array referenced by dest.
* The number of components copied is equal to the length argument.
* @param array $arrSrc - Source array to be copied
* @param number $arrSrcPos - Start position in the source array
* @param array $arrDes - Destination array
* @param number $arrDesPos - Start position in the destination array
* @param number $lenght - Number of array elements to be copied
* @throws Exception when source or destination are not array
* @return array with the copied information
*/
function arrayCopy($arrSrc, $arrSrcPos, $arrDes, $arrDesPos, $lenght) {
if (! is_array ( $arrSrc )) {
throw new Exception ( 'arrSrc is not array.' );
}
if (! is_array ( $arrDes )) {
throw new Exception ( 'arrDes is not array.' );
}
$result = $arrDes;
for($i = $arrSrcPos; $i < $lenght; $i ++) {
$result [$arrDesPos + $i] = $arrSrc [$i];
}
return $result;
}
Por si alguien tiene dudas de como utilizarla, aquí un ejemplo:
$arrDest = arrayCopy ( $arrOrg, 0, $arrDest , 0, sizeof ( $arrOrg) );
Este ejemplo copia el contenido de $arrOrg dentro de $arrDest
Este comentario ha sido eliminado por el autor.
ResponderEliminaryou welcome, thanks for your comment
ResponderEliminarHi,
ResponderEliminarnice post. Well written article. Keep sharing
Cheers,
https://www.flowerbrackets.com/system-arraycopy-method-java/