pushing element onto beginning of an array?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawpoop@gmail.com

    pushing element onto beginning of an array?

    Hello all -

    What's the best way to put an element onto the beginning of an array?
    Currently the method I'm using is

    $data = array_merge(
    array("new first value"),
    $data
    );

    Is there a better way?
  • =?ISO-8859-15?Q?Iv=E1n_S=E1nchez_Ortega?=

    #2
    Re: pushing element onto beginning of an array?

    lawpoop@gmail.c om wrote:
    What's the best way to put an element onto the beginning of an array?
    Use the array_shift/unshift/push/pop family of functions.

    --
    ----------------------------------
    Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

    MSN:i_eat_s_p_a _m_for_breakfas t@hotmail.com
    Jabber:ivansanc hez@jabber.org ; ivansanchez@kde talk.net

    Comment

    • lawpoop@gmail.com

      #3
      Re: pushing element onto beginning of an array?

      On Mar 11, 9:10 am, Iván Sánchez Ortega <ivansanchez-...@rroba-
      escomposlinux.-.punto.-.orgwrote:
      lawp...@gmail.c om wrote:
      What's the best way to put an element onto the beginning of an array?
      >
      Use the array_shift/unshift/push/pop family of functions.
      >
      Thanks, Ivan.

      It looks like the function I want is array_unshift() .

      Comment

      Working...