<HTML ><HEAD ><TITLE >array_unshift</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Array functions" HREF="ref.array.html"><LINK REL="PREVIOUS" TITLE="array_splice" HREF="function.array-splice.html"><LINK REL="NEXT" TITLE="array_values" HREF="function.array-values.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><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-splice.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.array-values.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.array-unshift" >array_unshift</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN3788" ></A >array_unshift -- Push one or more elements onto the beginning of array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN3791" ></A ><H2 >Description</H2 ><DIV CLASS="funcsynopsis" ><P ></P ><P ><CODE ><CODE CLASS="FUNCDEF" >int array_unshift</CODE >(array array, mixed var, [<SPAN CLASS="optional" >...</SPAN >] );</CODE ></P ><P ></P ></DIV ><P > <B CLASS="function" >array_unshift()</B > prepends passed elements to the front of the <TT CLASS="parameter" ><I >array</I ></TT >. Note that the list of elements is prepended as a whole, so that the prepended elements stay in the same order. </P ><P > Returns the new number of elements in the <TT CLASS="parameter" ><I >array</I ></TT >. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 1. <B CLASS="function" >array_unshift()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 $queue = array("p1", "p3"); 3 array_unshift($queue, "p4", "p5", "p6"); 4 </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > This would result in $queue having 5 elements: "p4", "p5", "p6", "p1", and "p3". </P ><P > See also <A HREF="function.array-shift.html" ><B CLASS="function" >array_shift()</B ></A >, <A HREF="function.array-push.html" ><B CLASS="function" >array_push()</B ></A >, and <A HREF="function.array-pop.html" ><B CLASS="function" >array_pop()</B ></A >. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > This function was added in PHP 4.0. </P ></BLOCKQUOTE ></DIV > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.array-splice.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.array-values.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >array_splice</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.array.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >array_values</TD ></TR ></TABLE ></DIV ></BODY ></HTML >