View Single Post
Old 01-20-2008, 06:23 PM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
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.
Thanks! :D That gave me the exact answer I wanted! :]
Orc is offline  
Reply With Quote