The short answer to your question is: Yes, if you access it for writing, PHP will create an array but not always!
To be more specific:
$b[2] = 'two'; - will create an array and will store the string two at key 2;
$c[] = 'zero'; - will create an array and will store the string zero at key 0;
echo $d[1] - will NOT create an array; and it will NOT create $d[1] if $d already is an array but it doesn't have the key 1.
You can check all these for yourself using print_r() or var_dump().
The complete answer is: DON'T do that! Always initialize the variables before using them!
Let me show you what happens when you ignore this advice and rely on PHP doing the initialization for you:
// Skip over the initialization of $a, PHP will do it for you
$a[1] = 'a';
$a = array_merge($a, array('b'));
print_r($a);
This code will produce the expected result:
Array
(
[0] => a
[1] => b
)
Now, let's say several hundreds lines of code above in the same function the code looks like this:
// Somewhere on top of the function (or file, if not in a function)
$a = 'blah';
$b = $a.', blah';
// there is no need for $a below this line but we don't bother
// to unset it, PHP will do it anyway at the end of the function
// ...
// a lot of code here that doesn't use $a
// ...
// several hundreds of lines below
// ...
// you forgot completely about the code on top
// ...
// and write new code as below:
// Skip over the initialization of $a, PHP will do it for you
$a[1] = 'a';
array_merge($a);
Oops, array_merge() failed with the message PHP Warning: array_merge(): Argument #1 is not an array.
What happened?
You expects that PHP will construct an array for you because you have used $a like $a[1] = 'b';
But PHP doesn't work this way!
It cannot guess what are you thinking. Variable $a already existed (it was created on top of the function and nobody unset it) and was holding a string. Because the notation $a[1] = 'b'; is a valid way to change a single character of a string, PHP just did that, completely unaware that you wish it to create an array.
Conclusion?
Always, but always initialize your variables just before you use them. Never expect that PHP or some fairies will do that for you. Maybe they do it now but they may change their mind tomorrow and suddenly your code will stop working or it will start producing bad results.