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 Link to comment https://forums.phpfreaks.com/topic/181427-purpose-of-array-function/ 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. Link to comment https://forums.phpfreaks.com/topic/181427-purpose-of-array-function/#findComment-957050 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 Link to comment https://forums.phpfreaks.com/topic/181427-purpose-of-array-function/#findComment-957051 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', ); Link to comment https://forums.phpfreaks.com/topic/181427-purpose-of-array-function/#findComment-957054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.