note 17593 modified in function.array-slice by vrana

From: Date: Tue, 17 Aug 2004 14:49:35 +0000
Subject: note 17593 modified in function.array-slice by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79919@lists.php.net to get a copy of this message
Here is a version of Array_slice which takes into account keys. That may be a suggestion for future developpement. <?php function array_slice_key($array, $offset){ if (!is_array($array)) return FALSE; if (func_num_args() == 3){ $length = func_get_arg(2); $length = max(0,intval($length)); } else { $length = count($array); } $i = 0; $return = array(); $keys = array_slice(array_keys($array), $offset, $length); foreach( $keys as $key){ $return[$key] = $array[$key]; } return $return; } ?> --was-- Here is a version of Array_slice which takes into account keys. That may be a suggestion for future developpement. function array_slice_key($array, $offset){ if (!is_array($array)) return FALSE; if (func_num_args() == 3){ $length = func_get_arg(2); $length = max(0,intval($length)); } else { $length = count($array); } $i = 0; $return = array(); $keys = array_slice(array_keys($array), $offset, $length); foreach( $keys as $key){ $return[$key] = $array[$key]; } return $return; } http://php.net/manual/en/function.array-slice.php

« previous php.notes (#79919) next »