note 98028 deleted from function.array-slice by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: benoit dot montuelle at gmail dot com 

----

Updated version of narray_slice function below, syntax-compatible with php 4 and php 5  servers.

It also works for text-index arrays

function narray_slice($array, $offset, $length, $preserve_keys = false) {

    //Check if this version already supports it
    if (version_compare(PHP_VERSION, '5.0.2', '>=')){
      return array_slice($array, $offset, $length, $preserve_keys);
    }
    else if ($preserve_keys == false) {
      return array_slice($array, $offset, $length);
    }

    $a = 0;
    foreach ($array as $key => $value) {

        if ($a >= $offset && $a - $offset < $length)
            $output_array[$key] = $value;
        $a++;

    }

    return $output_array;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.