note 73882 deleted from function.array-slice by cmb

From: Date: Sun, 29 Dec 2019 12:33:13 +0000
Subject: note 73882 deleted from function.array-slice by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213712@lists.php.net to get a copy of this message
Note Submitter: ---- I noticed that some other people made supportive functions for maintaining numeric keys for PHP versions less than 5.0.2. So here is my version of it. <?php //Slice an array but keep numeric keys function narray_slice($array, $offset, $length) { //Check if this version already supports it if (str_replace('.', '', PHP_VERSION) >= 502) return array_slice($array, $offset, $length, true); foreach ($array as $key => $value) { if ($a >= $offset && $a - $offset <= $length) $output_array[$key] = $value; $a++; } return $output_array; } ?>

« previous php.notes (#213712) next »