what is the array() function

Hi, in a piece of code, what is the array function and what does it do?

if(!is_array($copy)) $copy = array();
Who is Participating?
RoonaanConnect With a Mentor Commented:
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"

bryanlloydharrisAuthor Commented:
Oh I see, but you have to admit it looks just like a function (-:
It's a language construct, just like list($a, $b) = array('valueForA', 'valueForB'); (syntax to set $a to 'valueForA', and $b to 'valueForB');

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.