<HTML ><HEAD ><TITLE >array_slice</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Array Functions" HREF="ref.array.html"><LINK REL="PREVIOUS" TITLE="array_shift" HREF="function.array-shift.html"><LINK REL="NEXT" TITLE="array_splice" HREF="function.array-splice.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.array-shift.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.array-splice.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.array-slice" ></A >array_slice</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8090" ></A ><P > (PHP 4 )</P >array_slice -- Extract a slice of the array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8093" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_slice</B > ( array array, int offset [, int length])<BR ></BR ><P > <B CLASS="function" >array_slice()</B > returns the sequence of elements from the array <TT CLASS="parameter" ><I >array</I ></TT > as specified by the <TT CLASS="parameter" ><I >offset</I ></TT > and <TT CLASS="parameter" ><I >length</I ></TT > parameters. </P ><P > If <TT CLASS="parameter" ><I >offset</I ></TT > is positive, the sequence will start at that offset in the <TT CLASS="parameter" ><I >array</I ></TT >. If <TT CLASS="parameter" ><I >offset</I ></TT > is negative, the sequence will start that far from the end of the <TT CLASS="parameter" ><I >array</I ></TT >. </P ><P > If <TT CLASS="parameter" ><I >length</I ></TT > is given and is positive, then the sequence will have that many elements in it. If <TT CLASS="parameter" ><I >length</I ></TT > is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from <TT CLASS="parameter" ><I >offset</I ></TT > up until the end of the <TT CLASS="parameter" ><I >array</I ></TT >. </P ><P > Note that <B CLASS="function" >array_slice()</B > will ignore array keys, and will calculate offsets and lengths based on the actual positions of elements within the array. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8125" ></A ><P ><B >Example 1. <B CLASS="function" >array_slice()</B > examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$input = array ("a", "b", "c", "d", "e"); $output = array_slice ($input, 2); // returns "c", "d", and "e" $output = array_slice ($input, 2, -1); // returns "c", "d" $output = array_slice ($input, -2, 1); // returns "d" $output = array_slice ($input, 0, 3); // returns "a", "b", and "c"</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.array-splice.html" ><B CLASS="function" >array_splice()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.array-shift.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.array-splice.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >array_shift</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.array.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >array_splice</TD ></TR ></TABLE ></DIV ></BODY ></HTML >