SchweppesAle Posted November 13, 2009 Share Posted November 13, 2009 Was just wondering what the difference is between the following lines of code. Is the array() function faster maybe? $array['blah'] = 'output'; echo $array['blah']; //returns output or $array = array('blah' => 'output'); echo $array['blah']; //returns output Quote Link to comment Share on other sites More sharing options...
Alex Posted November 13, 2009 Share Posted November 13, 2009 Array() isn't a function. It's a language construct, there's really no benefit to doing it either way, for the most part it's just different ways of doing things. But say you're putting 10 objects into an array, it would be easier to use the Array() language construct than to rewrite $array['index'].. 10 times. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted November 13, 2009 Share Posted November 13, 2009 array() is more convenient if you're adding lots of values to an array $array=array('blah'=>'output','wha?'=>'input','whatever'=>'aux','etc'=>'somethingwitty'); that's the only difference, there's no real performance hit either way Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 13, 2009 Share Posted November 13, 2009 And it looks nice if you indent it well: $array = array( 'blah' => 'output', 'wha?' => 'input', 'whatever' => 'aux', 'etc' => 'somethingwitty', ); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.