what is the array() function

Posted on 2006-06-02
Last Modified: 2008-03-06
Hi, in a piece of code, what is the array function and what does it do?

if(!is_array($copy)) $copy = array();
Question by:bryanlloydharris
    LVL 49

    Accepted Solution

    it is a way to create an array. It is not realy a function.

    An array is sort of a list.

    You can initialize with any number of elements:

    $emptyArray = array();
    $oneItemArray = array('item');
    echo $oneItemArray[0]; // => "item"
    $twoItemArray = array('item 1', 'item 2');
    echo $oneItemArray[0]; // => "item 1"
    echo $oneItemArray[1]; // => "item 2"

    LVL 3

    Author Comment

    Oh I see, but you have to admit it looks just like a function (-:
    LVL 49

    Expert Comment

    It's a language construct, just like list($a, $b) = array('valueForA', 'valueForB'); (syntax to set $a to 'valueForA', and $b to 'valueForB');


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    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 …
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    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

    16 Experts available now in Live!

    Get 1:1 Help Now