View Single Post
Old 01-20-2008, 06:02 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

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.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
The Following 2 Users Say Thank You to Alan @ CIT For This Useful Post:
ETbyrne (01-20-2008), Orc (01-20-2008)