What is the best way to copy/delete an array in php

Posted on 2011-05-06
Last Modified: 2012-05-11
whats the best way to copy the first num of element in an array in php?
is there a function that do it? (can also cut the other side instead)
Question by:Nura111
    LVL 107

    Accepted Solution

    array_pop() will take the last element off an array.
    array_slice() will take the first element
    unset() will delete an array.

    These are all documented on the web site.
    LVL 107

    Expert Comment

    by:Ray Paseur
    Some of the array functions act as if the &array notation is used, so it is wise to read the descriptions carefully.  They are all very old PHP functions and date from the times when we got the needle-haystack confusion of function arguments.  Check the left sidebar of this page for a list of the array functions.  HTH, ~Ray

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now