• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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();
0
bryanlloydharris
Asked:
bryanlloydharris
  • 2
1 Solution
 
RoonaanCommented:
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"

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

-r-
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now