$variable = array(0);
$variable = array();
how are they different?
$variable = array(0);
$variable = array();
how are they different?
The first populates an array with a number 0, the latter is an empty array.
In the first case :
$variable = array(0);
var_dump($variable);
You get :
array
0 => int 0
ie, an array with an element whose value is 0.
And, in the second case :
$variable = array();
var_dump($variable);
you get :
array
empty
ie, an empty array.
The first contains a single element, a integer zero. The parameter is not a "size initializer" as you might imagine. You can see this by using var_dump on them:
$foo = array(0);
var_dump($foo);
$bar = array();
var_dump($bar);
This outputs
array(1) {
[0]=>
int(0)
}
array(0) {
}
In addition to meder:
$variable = array(0); count($variable); // 1 empty($variable); // false (!$variable) // false $variable = array(); count($variable); // 0 empty($variable); // true (!$variable) // true