note 98028 added to function.array-slice

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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;
}
----
Server IP: 89.31.146.176
Probable Submitter: 193.252.58.53
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit        -- https://master.php.net/note/edit/98028
Del: integrated  -- https://master.php.net/note/delete/98028/integrated
Del: useless     -- https://master.php.net/note/delete/98028/useless
Del: bad code    -- https://master.php.net/note/delete/98028/bad+code
Del: spam        -- https://master.php.net/note/delete/98028/spam
Del: non-english -- https://master.php.net/note/delete/98028/non-english
Del: in docs     -- https://master.php.net/note/delete/98028/in+docs
Del: other reasons-- https://master.php.net/note/delete/98028
Reject      -- https://master.php.net/note/reject/98028
Search      -- https://master.php.net/manage/user-notes.php
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.