A
is better. B
will result in a PHP Notice
when run, but will still work the same. As some other people mentioned and I overlooked initially, A
will also make your code more robust by making sure that $array
is what you want it to be when you need it and not some other variable type or previously defined variable.
Edit: the one time PHP doesn't throw a notice when using an undefined variable is when appending to an uninitialized array. From php.net:
E_NOTICE level error is issued in case of working with uninitialized variables, however not in the case of appending elements to the uninitialized array.