01-20-2008, 06:02 PM
|
#2 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
They are both valid ways but you end up with slightly different results.
PHP Code:
<?php
(array) $foo;
$bar = array();
var_dump($foo); // echo's "NULL"
var_dump($bar); // echo's "array(0) ( )
So as you can see, typesetting the variable to an array using (array) doesn't actually create a new empty array where as array() will.
For the sake of standards, you should probably use array() when creating new arrays. Things like (array) (int) (long) etc are generally only used when converting a variable type to another:
PHP Code:
<?php
$foo = 16.123;
$bar = (int) $foo;
var_dump($bar); // echo's int(16)
In this example, we have Long ($foo) which we then convert to an int by typecasting it using (int).
Alan.
|
|
|