Member Avatar for napninjanx

Which of the following correctly sets up a PHP array??

  1. array() = $array_values[];

  2. $array_values = array();

  3. array() = $array_values[];

  4. $array_values = new array();

Member Avatar for napninjanx

I think It's 2 right?

$array = array();

you don't need to declare before hand either you can use:

$array[] = $value;//add to end
$array[2] = $value;//add/overwrite entry with key of 2

1, 3 and 4 are wrong in php, 4 is the javascript to declare an array and 2 is correct

yeap...2 is correct.

Member Avatar for napninjanx

Thanks for the info.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.