<HTML ><HEAD ><TITLE >array_push</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_pop" HREF="function.array-pop.html"><LINK REL="NEXT" TITLE="array_rand" HREF="function.array-rand.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-pop.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-rand.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.array-push" ></A >array_push</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7878" ></A ><P > (PHP 4 )</P >array_push -- Push one or more elements onto the end of array </DIV ><DIV CLASS="refsect1" ><A NAME="AEN7881" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >array_push</B > ( array array, mixed var [, mixed ...])<BR ></BR ><P > <B CLASS="function" >array_push()</B > treats <TT CLASS="parameter" ><I >array</I ></TT > as a stack, and pushes the passed variables onto the end of <TT CLASS="parameter" ><I >array</I ></TT >. The length of <TT CLASS="parameter" ><I >array</I ></TT > increases by the number of variables pushed. Has the same effect as: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array[] = $var;</PRE ></TD ></TR ></TABLE > repeated for each <TT CLASS="parameter" ><I >var</I ></TT >. </P ><P > Returns the new number of elements in the array. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7904" ></A ><P ><B >Example 1. <B CLASS="function" >array_push()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$stack = array ("orange", "banana"); array_push ($stack, "apple", "raspberry");</PRE ></TD ></TR ></TABLE ><P > This example would result in <TT CLASS="varname" >$stack</TT > having the following elements: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >Array ( [0] => orange [1] => banana [2] => apple [3] => raspberry )</PRE ></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.array-pop.html" ><B CLASS="function" >array_pop()</B ></A >, <A HREF="function.array-shift.html" ><B CLASS="function" >array_shift()</B ></A >, and <A HREF="function.array-unshift.html" ><B CLASS="function" >array_unshift()</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-pop.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-rand.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >array_pop</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_rand</TD ></TR ></TABLE ></DIV ></BODY ></HTML >